本文整理汇总了Java中rice.selector.TimerTask类的典型用法代码示例。如果您正苦于以下问题:Java TimerTask类的具体用法?Java TimerTask怎么用?Java TimerTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TimerTask类属于rice.selector包,在下文中一共展示了TimerTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: BandwidthMeasuringTransportLayer
import rice.selector.TimerTask; //导入依赖的package包/类
public BandwidthMeasuringTransportLayer(int measurementPeriod, TransportLayer<Identifier, ByteBuffer> tl, Environment env) {
this.tl = tl;
tl.setCallback(this);
this.measurementPeriod = measurementPeriod;
this.logger = env.getLogManager().getLogger(BandwidthMeasuringTransportLayer.class, null);
this.errorHandler = new DefaultErrorHandler<Identifier>(logger);
this.time = env.getTimeSource();
this.lastMeasure = time.currentTimeMillis();
env.getSelectorManager().schedule(new TimerTask() {
@Override
public void run() {
measure();
}
},measurementPeriod,measurementPeriod);
}
示例2: startAuditTimer
import rice.selector.TimerTask; //导入依赖的package包/类
protected void startAuditTimer() {
long now = peerreview.getTime();
long nextTimeout = lastAuditStarted + (long)((500+(peerreview.getRandomSource().nextInt(1000)))*0.001*auditIntervalMillis);
if (nextTimeout <= now) {
nextTimeout = now + 1;
}
auditTimer = peerreview.getEnvironment().getSelectorManager().schedule(new TimerTask() {
@Override
public void run() {
auditsTimerExpired();
}
},nextTimeout-now);
}
示例3: CommitmentProtocolImpl
import rice.selector.TimerTask; //导入依赖的package包/类
public CommitmentProtocolImpl(PeerReview<Handle,Identifier> peerreview,
IdentityTransport<Handle, Identifier> transport,
PeerInfoStore<Handle, Identifier> infoStore, AuthenticatorStore<Identifier> authStore,
SecureHistory history,
long timeToleranceMillis) throws IOException {
this.peerreview = peerreview;
this.transport = transport;
this.infoStore = infoStore;
this.authStore = authStore;
this.history = history;
this.nextReceiveCacheEntry = 0;
// this.numPeers = 0;
this.timeToleranceMillis = timeToleranceMillis;
this.logger = peerreview.getEnvironment().getLogManager().getLogger(CommitmentProtocolImpl.class, null);
initReceiveCache();
makeProgressTask = new TimerTask(){
@Override
public void run() {
makeProgressAllPeers();
}
};
peerreview.getEnvironment().getSelectorManager().schedule(makeProgressTask, PROGRESS_INTERVAL_MILLIS, PROGRESS_INTERVAL_MILLIS);
}
示例4: notifyStatusChange
import rice.selector.TimerTask; //导入依赖的package包/类
public void notifyStatusChange(final Identifier id, final int newStatus) {
// char buf1[256];
if (logger.level <= Logger.INFO) logger.log("Status change: <"+id+"> becomes "+getStatusString(newStatus));
// logger.logException("Status change: <"+id+"> becomes "+getStatusString(newStatus),new Exception("Stack Trace"));
challengeProtocol.notifyStatusChange(id, newStatus);
commitmentProtocol.notifyStatusChange(id, newStatus);
// let pr finish first
env.getSelectorManager().schedule(new TimerTask() {
public void run() {
callback.notifyStatusChange(id, newStatus);
}
public String toString() {
return "NotifyStatusChangeTask: "+id+"=>"+newStatus;
}
}, 3);
}
示例5: registerForWriteWithTimeout
import rice.selector.TimerTask; //导入依赖的package包/类
private void registerForWriteWithTimeout(final P2PSocketReceiver<Identifier> receiver) {
if (logger.level <= Logger.FINE) logger.log(EntityManager.this+"registerForWriteWithTimeout()");
hasRegisterCalledBack = new AtomicBoolean();
TimerTask registerTimeoutTask = new TimerTask() {
@Override
public void run() {
if (!hasRegisterCalledBack.get()) {
String message = EntityManager.this+"No callback for register for BIG message to " + i;
if (logger.level <= Logger.FINE) logger.log(message);
receiveException(socket, new IOException(message));
//registerForWriteWithTimeout(receiver);
}
}
};
registerTimerTask = selectorManager.schedule(registerTimeoutTask, REGISTER_TIMEOUT_SECONDS * 1000);
socket.register(false, true, receiver);
}
示例6: start
import rice.selector.TimerTask; //导入依赖的package包/类
public void start(final Map<String,Object> options) {
if (logger.level <= Logger.FINE) logger.log(EntityManager.this+"Opening BIG message socket to: "+i);
hasOpenSocketCalledBack = new AtomicBoolean();
TimerTask openSocketTimeoutTask = new TimerTask() {
@Override
public void run() {
if (!hasOpenSocketCalledBack.get()) {
if (logger.level <= Logger.FINE) logger.log(EntityManager.this+"No callback for open-socket for BIG message to " + i + ", so retrying");
PendingMessages.this.start(options);
}
}
};
openTimerTask = selectorManager.schedule(openSocketTimeoutTask, OPEN_TIMEOUT_SECONDS * 1000);
tl.openSocket(i, this, options);
}
示例7: forceClose
import rice.selector.TimerTask; //导入依赖的package包/类
/**
* Called when we force a socket closed.
*
*/
public void forceClose() {
// logger.log(this+".forceClose()");
if (logger.level <= Logger.FINE) logger.log(this+".forceClose()");
forcedClose = true;
super.shutdownOutput();
// super.close();
timer.schedule(new TimerTask() {
@Override
public void run() {
try {
close();
} catch (Exception ioe) {
// do nothing, it's probably already closed anyway
}
}
}, 3000);
}
示例8: BandwidthLimitingTransportLayer
import rice.selector.TimerTask; //导入依赖的package包/类
/**
* To send 10K/second specify use
*
* 10240,1000
*
* @param bucketSize bytes to send
* @param bucketTimelimit in millis
*/
public BandwidthLimitingTransportLayer(
TransportLayer<Identifier, ByteBuffer> tl,
int bucketSize, int bucketTimelimit,
Environment env) {
this.environment = env;
this.tl = tl;
BUCKET_SIZE = bucketSize;
BUCKET_TIME_LIMIT = bucketTimelimit;
logger = env.getLogManager().getLogger(BandwidthLimitingTransportLayer.class, null);
this.errorHandler = new DefaultErrorHandler<Identifier>(logger);
tl.setCallback(this);
environment.getSelectorManager().getTimer().schedule(new TimerTask(){
@Override
public void run() {
// always synchronize on "this" before modifying the bucket
synchronized(this) {
bucket = BUCKET_SIZE;
for (BandwidthLimitingSocket s : sockets) {
s.notifyBandwidthRefilled();
}
}
}
}, 0, BUCKET_TIME_LIMIT);
}
示例9: executeTask
import rice.selector.TimerTask; //导入依赖的package包/类
@Override
public boolean executeTask(final TimerTask next) {
executeTaskLoggerConfiguration.setCallableToRun(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
if (LOG.isDebugEnabled())
LOG.debug("Execute Task: " + next);
boolean result = next.execute(timeSource);
return result;
}
});
executeTaskLoggerConfiguration.setLogHeader(getClass().getSimpleName() + ".executeTask(" + next + ")");
try {
return executeTaskLogger.call();
} catch (Exception e) {
LOG.warn("Error executing task: " + next);
return false;
}
}
示例10: addTask
import rice.selector.TimerTask; //导入依赖的package包/类
@Override
public void addTask(final TimerTask task) {
addTaskLoggerConfiguration.setCallableToRun(new Callable<Void>() {
@Override
public Void call() throws Exception {
callAddTask(task);
return null;
}
});
addTaskLoggerConfiguration.setLogHeader(getClass().getSimpleName() + ".addTask(" + task + ")");
try {
addTaskLogger.call();
} catch (Exception e) {
LOG.warn("Exception during add task for task " + task, e);
}
}
示例11: callAddTask
import rice.selector.TimerTask; //导入依赖的package包/类
private void callAddTask(TimerTask task) {
if (LOG.isDebugEnabled())
LOG.debug(String.format("addTask(%s)", task));
if (!piTimerQueue.add(task)) {
LOG.error("ERROR: Got false while enqueueing task " + task + "!");
} else {
task.setSelectorManager(this);
}
// need to interrupt thread if waiting too long in selector
if (select) {
// using the network
if (wakeupTime >= task.scheduledExecutionTime()) {
// we need to wake up the selector because it's going to sleep too long
wakeup();
}
} else {
// using the simulator
if (task.scheduledExecutionTime() == getNextTaskExecutionTime()) {
// we need to wake up the selector because we are now the newest
// shortest wait, and may be delaying because of a later event
wakeup();
}
}
}
示例12: start
import rice.selector.TimerTask; //导入依赖的package包/类
private void start()
{
try
{
// create the environment
final PPSSetup ppss = new PPSSetup(bootAddress, bootPort, bindPort);
// XXX replace this with the actual data source
ValueReaderFactory valueReaderFactory = new GaussianValueReaderFactory(2, 1, 1, ppss.getEnvironment().getRandomSource());
// boot node
ppss.scheduleJoiningNodes(STEP_SIZE, 1, valueReaderFactory, STEP_SIZE, updateInterval, min, max, traceMessages, new TimerTask()
{
@Override
public void run()
{
// schedule logging
ppss.scheduleObservation(0, STEP_SIZE, 1);
}
});
}
catch (IOException e)
{
e.printStackTrace();
}
}
示例13: AuditProtocolImpl
import rice.selector.TimerTask; //导入依赖的package包/类
public AuditProtocolImpl(PeerReview<Handle, Identifier> peerreview,
SecureHistory history, PeerInfoStore<Handle, Identifier> infoStore,
AuthenticatorStore<Identifier> authInStore,
IdentityTransport<Handle, Identifier> transport,
AuthenticatorStore<Identifier> authOutStore,
EvidenceTransferProtocol<Handle, Identifier> evidenceTransferProtocol,
AuthenticatorStore<Identifier> authCacheStore) {
this.logger = peerreview.getEnvironment().getLogManager().getLogger(AuditProtocolImpl.class, null);
this.peerreview = peerreview;
this.history = history;
this.infoStore = infoStore;
this.authInStore = authInStore;
this.transport = transport;
this.authOutStore = authOutStore;
this.evidenceTransferProtocol = evidenceTransferProtocol;
this.authCacheStore = authCacheStore;
this.progressTimer = null;
this.logDownloadTimeout = DEFAULT_LOG_DOWNLOAD_TIMEOUT;
this.replayEnabled = true;
this.lastAuditStarted = peerreview.getTime();
this.auditIntervalMillis = DEFAULT_AUDIT_INTERVAL_MILLIS;
auditTimer = peerreview.getEnvironment().getSelectorManager().schedule(new TimerTask() {
@Override
public void run() {
auditsTimerExpired();
}},auditIntervalMillis);
}
示例14: scheduleProgressTimer
import rice.selector.TimerTask; //导入依赖的package包/类
protected void scheduleProgressTimer() {
if (progressTimer == null) {
progressTimer = peerreview.getEnvironment().getSelectorManager().schedule(new TimerTask() {
@Override
public void run() {
makeProgressTimerExpired();
}}, PROGRESS_INTERVAL_MILLIS);
}
}
示例15: makeProgressTimerExpired
import rice.selector.TimerTask; //导入依赖的package包/类
/**
* While some audits haven't finished, we must call makeProgress() regularly
*/
protected void makeProgressTimerExpired() {
progressTimer.cancel();
cleanupAudits();
makeProgressOnInvestigations();
if (progressTimer == null && ((activeAudit.size() > 0) || (activeInvestigation.size() > 0))) {
progressTimer = peerreview.getEnvironment().getSelectorManager().schedule(new TimerTask() {
@Override
public void run() {
makeProgressTimerExpired();
}
}, PROGRESS_INTERVAL_MILLIS);
}
}