本文整理汇总了Java中net.tomp2p.utils.Utils.addReleaseListenerAll方法的典型用法代码示例。如果您正苦于以下问题:Java Utils.addReleaseListenerAll方法的具体用法?Java Utils.addReleaseListenerAll怎么用?Java Utils.addReleaseListenerAll使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.tomp2p.utils.Utils
的用法示例。
在下文中一共展示了Utils.addReleaseListenerAll方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testRPC1
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
@Test
public void testRPC1() throws Exception {
Peer peer1 = null;
Peer peer2 = null;
try {
peer1 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4001).setEnableTask(true)
.makeAndListen();
peer2 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4002).setEnableTask(true)
.makeAndListen();
FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(1);
futureChannelCreator.awaitUninterruptibly();
Number160 taskId = new Number160(11);
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
dataMap.put(new Number160(22), new Data("testme"));
FutureResponse futureResponse = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId, dataMap, new MyWorker1(), null, false, false);
Utils.addReleaseListenerAll(futureResponse, peer1.getConnectionBean().getConnectionReservation(),
futureChannelCreator.getChannelCreator());
futureResponse.awaitUninterruptibly();
Assert.assertEquals(true, futureResponse.isSuccess());
Thread.sleep(1000);
} finally {
if (peer1 != null) {
peer1.halt();
}
if (peer2 != null) {
peer2.halt();
}
}
}
示例2: testRPCAsync
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
@Test
public void testRPCAsync() throws Exception {
Peer peer1 = null;
Peer peer2 = null;
try {
peer1 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4001).setEnableTask(true)
.makeAndListen();
peer2 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4002).setEnableTask(true)
.makeAndListen();
FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(1);
futureChannelCreator.awaitUninterruptibly();
Number160 taskId = new Number160(11);
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
dataMap.put(new Number160(22), new Data("testme"));
FutureAsyncTask futureAsyncTask = peer1.getAsyncTask().submit(peer2.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId, dataMap, new MyWorker3(), false, false);
Utils.addReleaseListenerAll(futureAsyncTask, peer1.getConnectionBean().getConnectionReservation(),
futureChannelCreator.getChannelCreator());
futureAsyncTask.awaitUninterruptibly();
Assert.assertEquals(true, futureAsyncTask.isSuccess());
Assert.assertEquals("yup", futureAsyncTask.getDataMap().get(Number160.ONE).getObject());
} catch (Throwable t) {
t.printStackTrace();
} finally {
if (peer1 != null) {
peer1.halt();
}
if (peer2 != null) {
peer2.halt();
}
}
}
示例3: testRPCAsyncFailed
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
@Test
public void testRPCAsyncFailed() throws Exception {
Peer peer1 = null;
Peer peer2 = null;
try {
peer1 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4001).setEnableTask(true)
.makeAndListen();
peer2 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4002).setEnableTask(true)
.makeAndListen();
FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(1);
futureChannelCreator.awaitUninterruptibly();
Number160 taskId = new Number160(11);
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
dataMap.put(new Number160(22), new Data("testme"));
FutureAsyncTask futureAsyncTask = peer1.getAsyncTask().submit(peer2.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId, dataMap, new MyWorker3(), false, false);
Utils.addReleaseListenerAll(futureAsyncTask, peer1.getConnectionBean().getConnectionReservation(),
futureChannelCreator.getChannelCreator());
peer2.halt();
futureAsyncTask.awaitUninterruptibly();
Assert.assertEquals(false, futureAsyncTask.isSuccess());
} finally {
if (peer1 != null) {
peer1.halt();
}
}
}
示例4: testRPC2
import net.tomp2p.utils.Utils; //导入方法依赖的package包/类
@Test
public void testRPC2() throws Exception {
Peer peer1 = null;
Peer peer2 = null;
try {
peer1 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4001).setEnableTask(true)
.makeAndListen();
peer2 = new PeerMaker(new Number160(rnd)).setWorkerThreads(1).setPorts(4002).setEnableTask(true)
.makeAndListen();
FutureChannelCreator futureChannelCreator = peer1.getConnectionBean().getConnectionReservation().reserve(5);
futureChannelCreator.awaitUninterruptibly();
Number160 taskId1 = new Number160(11);
Number160 taskId2 = new Number160(12);
Number160 taskId3 = new Number160(13);
Map<Number160, Data> dataMap = new HashMap<Number160, Data>();
dataMap.put(new Number160(22), new Data("testme"));
FutureResponse futureResponse1 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId1, dataMap, new MyWorker2(), null, false, false);
futureResponse1.awaitUninterruptibly();
FutureResponse futureResponse2 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId2, dataMap, new MyWorker2(), null, false, false);
futureResponse2.awaitUninterruptibly();
FutureResponse futureResponse3 = peer1.getTaskRPC().sendTask(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskId3, dataMap, new MyWorker2(), null, false, false);
futureResponse3.awaitUninterruptibly();
Assert.assertEquals(true, futureResponse1.isSuccess());
Assert.assertEquals(true, futureResponse2.isSuccess());
Assert.assertEquals(true, futureResponse3.isSuccess());
Collection<Number160> taskIDs = new ArrayList<Number160>();
taskIDs.add(taskId1);
taskIDs.add(taskId2);
taskIDs.add(taskId3);
FutureResponse futureResponse4 = peer1.getTaskRPC().taskStatus(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskIDs, false);
futureResponse4.awaitUninterruptibly();
Assert.assertEquals(3, futureResponse4.getResponse().getDataMap().size());
Map<Number160, Data> map = futureResponse4.getResponse().getDataMap();
TaskStatus status1 = (TaskStatus) map.get(taskId1).getObject();
TaskStatus status2 = (TaskStatus) map.get(taskId2).getObject();
TaskStatus status3 = (TaskStatus) map.get(taskId3).getObject();
Assert.assertEquals(TaskStatus.Status.STARTED, status1.getStatus());
Assert.assertEquals(TaskStatus.Status.QUEUE, status2.getStatus());
Assert.assertEquals(0, status2.getQueuePosition());
Assert.assertEquals(TaskStatus.Status.QUEUE, status3.getStatus());
Assert.assertEquals(1, status3.getQueuePosition());
Thread.sleep(1000);
FutureResponse futureResponse5 = peer1.getTaskRPC().taskStatus(peer1.getPeerAddress(),
futureChannelCreator.getChannelCreator(), taskIDs, false);
Utils.addReleaseListenerAll(futureResponse5, peer1.getConnectionBean().getConnectionReservation(),
futureChannelCreator.getChannelCreator());
futureResponse5.awaitUninterruptibly();
Assert.assertEquals(3, futureResponse5.getResponse().getDataMap().size());
map = futureResponse5.getResponse().getDataMap();
status1 = (TaskStatus) map.get(taskId1).getObject();
status2 = (TaskStatus) map.get(taskId2).getObject();
status3 = (TaskStatus) map.get(taskId3).getObject();
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status1.getStatus());
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status2.getStatus());
Assert.assertEquals(TaskStatus.Status.SUCCESS_RESULT_SENT, status3.getStatus());
} finally {
if (peer1 != null) {
peer1.halt();
}
if (peer2 != null) {
peer2.halt();
}
}
}