Commit 41406be8 authored by toaster's avatar toaster
Browse files

audit-core stubs

git-svn-id: https://subversion.umiacs.umd.edu/ace/trunk@123 f1b3a171-7291-4a19-a512-95ad0ad9394a
parent 0f90caab
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>ace</artifactId>
<groupId>edu.umiacs.ace</groupId>
<version>1.7-SNAPSHOT</version>
</parent>
<groupId>edu.umiacs.ace</groupId>
<artifactId>audit-core</artifactId>
<name>Core audit queue</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>edu.umiacs.ace</groupId>
<artifactId>ace-common</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
import edu.umiacs.ace.util.ThrottledInputStream;
import java.io.IOException;
import java.io.InputStream;
/**
*
* @author toaster
*/
public abstract class AuditItem {
private String name;
private long created;
private AuditSource source;
public AuditItem(String name, AuditSource source) {
this.name = name;
this.created = System.currentTimeMillis();
this.source = source;
}
public final AuditSource getSource() {
return source;
}
public abstract InputStream openStream() throws IOException;
public final String getName() {
return name;
}
public final long getCreated() {
return created;
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
/**
*
* @author toaster
*/
public interface AuditItemListener {
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import org.apache.log4j.Logger;
/**
*
* @author toaster
*/
public final class AuditQueue {
private static final Logger LOG = Logger.getLogger(AuditQueue.class);
private List<AuditSource> sourceList;
private boolean shutdown = false;
private Lock sourceLock = new ReentrantLock();
private int maxSources = 0;
private ExecutorService exePool = Executors.newCachedThreadPool();
public void setMaxSources(int maxSources) {
this.maxSources = maxSources;
}
public void startup() {
Thread t = new Thread(new QueueScanner());
t.setName("Audit Queue Runner");
t.start();
}
public void shutdown() {
sourceLock.lock();
try {
shutdown = true;
for (AuditSource as : sourceList) {
as.abort();
as.close();
}
} finally {
sourceLock.unlock();
}
}
public boolean isShutdown() {
return shutdown;
}
public boolean addAuditSource(AuditSource source) {
sourceLock.lock();
try {
if (sourceList.size() > maxSources) {
return false;
}
sourceList.add(source);
return true;
} finally {
sourceLock.unlock();
}
}
/**
*
* @return next item to be audited
*/
AuditItem nextItem() {
sourceLock.lock();
try {
if (sourceList.size() < 0) {
return null;
}
return null;
} finally {
sourceLock.unlock();
}
}
private class QueueScanner implements Runnable {
public void run() {
while (!shutdown) {
try
{
}
catch (Throwable t)
{
LOG.error(t);
}
}
}
private boolean isTakeAllowed(AuditSource as)
{
return true;
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
/**
*
* @author toaster
*/
public abstract class AuditSource {
private long lastTake = 0;
private int processingTasks = 0;
private Policy auditPolicy;
private boolean aborted;
protected abstract AuditItem loadNext();
protected abstract boolean moreItems();
public Policy getAuditPolicy() {
return auditPolicy;
}
/**
* Set the audit policy associated with this source.
*
* @param auditPolicy
*/
public void setAuditPolicy(Policy auditPolicy) {
this.auditPolicy = auditPolicy;
}
/**
*
* @return next item or null if none
*/
public AuditItem nextItem() {
if (!hasNext()) {
return null;
}
lastTake = System.currentTimeMillis();
return loadNext();
}
/**
* Return the last time an item was retrieved from this queue. Useful for
* building policy.
*
* @return
*/
public long getLastTake() {
return lastTake;
}
/**
* Tell all items from this source to immediately stop processing.
*/
public final void abort()
{
aborted = true;
notifyAbort();
}
/**
* No-op method. Implementers may override to receive
*
*/
protected void notifyAbort()
{
}
public final boolean isAborted() {
return aborted;
}
/**
* Determine if any more items will ever be available from this queue.
*
*
* @return false if aborted or driver has no more items, true otherwise
*/
public final boolean hasNext()
{
if (aborted)
return false;
return moreItems();
}
/**
* No-op method. Implementers may override to perform any source shutdown
* operations. No additional calls to any data retrieval (next, hasNext) will
* be called after this.
*
*/
public void close() {
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
/**
*
* @author toaster
*/
public class ItemProcessor implements Runnable{
private AuditItem ai;
public ItemProcessor(AuditItem ai) {
this.ai = ai;
}
public void run() {
throw new UnsupportedOperationException("Not supported yet.");
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package edu.umiacs.ace.audit;
/**
*
* @author toaster
*/
public final class Policy {
private long bps;
public long getBps() {
return bps;
}
public void setBps(long bps) {
this.bps = bps;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment