use of com.zx.sms.connect.manager.ExitUnlimitCirclePolicy in project SMSGate by Lihuanghe.
the class TestCirculeFutureTask method test.
@Test
public void test() {
final Thread th = Thread.currentThread();
EventLoopGroupFactory.INS.submitUnlimitCircleTask(new Callable<Integer>() {
private long lastime = 0;
@Override
public Integer call() throws Exception {
cnt++;
long now = System.nanoTime();
System.out.println(now - lastime);
lastime = now;
return cnt;
}
}, new ExitUnlimitCirclePolicy() {
@Override
public boolean notOver(Future future) {
try {
boolean ret = (Integer) future.get() < 100;
if (!ret) {
LockSupport.unpark(th);
}
return ret;
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
LockSupport.unpark(th);
return false;
}
}, 0);
System.out.println(ManagementFactory.getRuntimeMXBean().getName());
}
use of com.zx.sms.connect.manager.ExitUnlimitCirclePolicy in project SMSGate by Lihuanghe.
the class MessageReceiveHandler method userEventTriggered.
public synchronized void userEventTriggered(final ChannelHandlerContext ctx, Object evt) throws Exception {
synchronized (lock) {
if (evt == SessionState.Connect && !inited) {
EventLoopGroupFactory.INS.submitUnlimitCircleTask(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
long nowcnt = cnt.get();
EndpointConnector conn = getEndpointEntity().getSingletonConnector();
logger.info("channels : {},Totle Receive Msg Num:{}, speed : {}/s", conn == null ? 0 : conn.getConnectionNum(), nowcnt, (nowcnt - lastNum) / rate);
lastNum = nowcnt;
return true;
}
}, new ExitUnlimitCirclePolicy() {
@Override
public boolean notOver(Future future) {
inited = getEndpointEntity().getSingletonConnector().getConnectionNum() > 0;
return inited;
}
}, rate * 1000);
inited = true;
}
}
ctx.fireUserEventTriggered(evt);
}
Aggregations