本文整理汇总了Java中com.cloudhopper.commons.util.windowing.Window类的典型用法代码示例。如果您正苦于以下问题:Java Window类的具体用法?Java Window怎么用?Java Window使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Window类属于com.cloudhopper.commons.util.windowing包,在下文中一共展示了Window类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import com.cloudhopper.commons.util.windowing.Window; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
Window<Integer,String,String> window = new Window<Integer,String,String>(1);
WindowFuture<Integer,String,String> future = window.offer(0, "Request0", 1000);
logger.info("Request0 worked");
//requestFuture.await();
// add a response
WindowFuture<Integer,String,String> future0 = window.complete(0, "Response0");
logger.info(future0.getRequest());
logger.info(future0.getResponse());
// this should timeout dude...
WindowFuture<Integer,String,String> future1 = window.offer(1, "Request1", 1000);
logger.info("Request1 worked");
WindowFuture<Integer,String,String> future2 = window.complete(1, "Response1");
logger.info(future2.getRequest());
logger.info(future2.getResponse());
// cancel a request with an exception cause
WindowFuture<Integer,String,String> future3 = window.offer(2, "Request2", 1000);
Thread.sleep(100);
WindowFuture<Integer,String,String> future4 = window.fail(2, new Exception("Test Cause"));
logger.info("Request2 Done? " + future4.isDone());
logger.info("Request2 Success? " + future4.isSuccess());
logger.info("Request2 Cancelled? " + future4.isCancelled());
logger.info("Request2 Cause: ", future4.getCause());
logger.info("Request2 OfferToAccept: " + future4.getOfferToAcceptTime());
logger.info("Request2 OfferToDone: " + future4.getOfferToDoneTime());
logger.info("Request2 AcceptToDone: " + future4.getAcceptToDoneTime());
System.out.println("Press any key to exit...");
System.in.read();
}
示例2: main
import com.cloudhopper.commons.util.windowing.Window; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
WindowListener listener = new WindowListener<Integer,String,String>() {
@Override
public void expired(WindowFuture<Integer, String, String> entry) {
logger.debug("The key=" + entry.getKey() + ", request=" + entry.getRequest() + " expired");
}
};
Window<Integer,String,String> window = new Window<Integer,String,String>(2, executor, 5000, listener);
Window<Integer,String,String> window2 = new Window<Integer,String,String>(2, executor, 5000, listener, "window2monitor");
WindowFuture<Integer,String,String> future0 = window.offer(0, "Request0", 1000, 4000);
logger.info("Request0 offered at " + future0.getOfferTimestamp() + " and expires at " + future0.getExpireTimestamp());
//requestFuture.await();
System.out.println("Press any key to add another request...");
System.in.read();
WindowFuture<Integer,String,String> future1 = window2.offer(1, "Request1", 1000, 4000);
logger.info("Request1 offered at " + future1.getOfferTimestamp() + " and expires at " + future1.getExpireTimestamp());
System.out.println("Press any key to add response...");
System.in.read();
logger.info("Adding Response1...");
WindowFuture<Integer,String,String> responseFuture1 = window.complete(1, "Response1");
if (responseFuture1 == null) {
logger.info("Request1 was not present in window");
} else {
logger.info(responseFuture1.getRequest());
logger.info(responseFuture1.getResponse());
}
/**
// add a response
ResponseFuture<Integer,String,String> responseFuture0 = requestWindow.addResponse(0, "Response0");
logger.info(responseFuture0.getRequest());
logger.info(responseFuture0.getResponse());
logger.info("Processing Time: " + responseFuture0.getProcessingTime() + " ms");
// this should timeout dude...
RequestFuture<Integer,String,String> requestFuture1 = requestWindow.addRequest(1, "Request1", 1000);
logger.info("Request1 worked");
ResponseFuture<Integer,String,String> responseFuture1 = requestWindow.addResponse(1, "Response1");
logger.info(responseFuture1.getRequest());
logger.info(responseFuture1.getResponse());
logger.info("Processing Time: " + responseFuture1.getProcessingTime() + " ms");
*/
System.out.println("Press any key to get rid of our reference to Window");
System.in.read();
window.destroy();
window2.destroy();
window = null;
window2 = null;
System.gc();
System.out.println("Press any key to exit...");
System.in.read();
executor.shutdown();
}
示例3: sessionDestroyed
import com.cloudhopper.commons.util.windowing.Window; //导入依赖的package包/类
public void sessionDestroyed(SmppSession session) {
try {
accessSemaphore.acquire();
} catch (InterruptedException e) {
}
try {
if (logger.isInfoEnabled()) {
logger.info(String.format("Session destroyed: SystemId=%s", session.getConfiguration().getSystemId()));
}
// print out final stats
if (session.hasCounters()) {
logger.info(String.format("final session rx-submitSM: %s", session.getCounters().getRxSubmitSM()));
}
// remove esmeServer out of enquire list
String esmeName = session.getConfiguration().getName();
Esme esmeServer = this.esmeManagement.getEsmeByName(esmeName);
esmeServer.setServerBound(false);
esmeServer.resetEnquireLinkFail();
this.smppServerOpsThread.removeEnquireList(esmeName);
this.smppSessionHandlerInterface.destroySmppSessionHandler(esmeServer);
// bringing back to close
esmeServer.setLocalStateName((com.cloudhopper.smpp.SmppSession.STATES[SmppSession.STATE_CLOSED]));
DefaultSmppSession defaultSession = (DefaultSmppSession) session;
// firing of onPduRequestTimeout() for sent messages for which we do not have responses
Window<Integer, PduRequest, PduResponse> wind = defaultSession.getSendWindow();
Map<Integer, WindowFuture<Integer, PduRequest, PduResponse>> futures = wind.createSortedSnapshot();
for (WindowFuture<Integer, PduRequest, PduResponse> future : futures.values()) {
this.logger.warn("Firing of onPduRequestTimeout from DefaultSmppServerHandler.sessionDestroyed(): "
+ future.getRequest().toString());
defaultSession.expired(future);
}
// make sure it's really shutdown
session.destroy();
} finally {
accessSemaphore.release();
}
}