本文整理汇总了Java中org.jgroups.util.RspList类的典型用法代码示例。如果您正苦于以下问题:Java RspList类的具体用法?Java RspList怎么用?Java RspList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RspList类属于org.jgroups.util包,在下文中一共展示了RspList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getMemUsage
import org.jgroups.util.RspList; //导入依赖的package包/类
@Override
public long getMemUsage(String user) {
try {
if (iCheckLocal && iContainer.hasSolver(user))
return iContainer.getMemUsage(user);
RspList<Long> ret = iContainer.getDispatcher().callRemoteMethods(null, "getMemUsage", new Object[] { user }, new Class[] { String.class }, SolverServerImplementation.sAllResponses);
long total = 0, count = 0;
for (Rsp<Long> rsp : ret) {
if (rsp != null && rsp.getValue() != null && rsp.getValue() > 0) {
total += rsp.getValue();
count ++;
}
}
return count == 0 ? 0 : total / count;
} catch (Exception e) {
sLog.error("Failed to retrieve allocated memory " + user + ": " + e.getMessage(), e);
}
return 0;
}
示例2: cancelTask
import org.jgroups.util.RspList; //导入依赖的package包/类
@Override
public boolean cancelTask(String hostname) {
try {
log.debug("Calling cancelTaskRpc for {}...", hostname);
MethodCall call = new MethodCall(getClass().getMethod("cancelTaskRpc", String.class));
RequestOptions ops = new RequestOptions(ResponseMode.GET_ALL, 5000);
call.setArgs(hostname);
RspList<CancelTaskRpcResponse> responses = rpcDispatcher.callRemoteMethods(
rpcDispatcher.getChannel()
.getView()
.getMembers()
.stream()
.filter(h -> h.toString().equalsIgnoreCase(hostname))
.collect(Collectors.toList()),
call, ops);
log.debug("Got answer: {}", responses);
return responses.getResults()
.stream()
.anyMatch(CancelTaskRpcResponse::isCancelled);
} catch (Exception e) {
log.catching(e);
return false;
}
}
示例3: start
import org.jgroups.util.RspList; //导入依赖的package包/类
public void start() throws Exception {
int c;
RspList rsps;
channel=new JChannel(); // default props
disp=new RpcDispatcher(channel, null, this, this);
channel.connect("rpc-test");
while(true) {
System.out.println("[x]: exit [s]: send sync group RPC");
System.out.flush();
c=System.in.read();
switch(c) {
case 'x':
channel.close();
disp.stop();
return;
case 's':
rsps=sendGroupRpc();
System.out.println("responses:\n" + rsps);
break;
}
System.in.skip(System.in.available());
}
}
示例4: testMethodCallWithTimeoutNoInterrupt
import org.jgroups.util.RspList; //导入依赖的package包/类
public void testMethodCallWithTimeoutNoInterrupt() throws Exception {
long timeout, block_time;
RspList rsps;
timeout=0;
block_time=0;
rsps=call(timeout, block_time);
checkResults(rsps, 2, true);
timeout=0;
block_time=1000L;
rsps=call(timeout, block_time);
checkResults(rsps, 2, true);
timeout=1000;
block_time=0L;
rsps=call(timeout, block_time);
checkResults(rsps, 2, true);
timeout=1000;
block_time=10000L;
rsps=call(timeout, block_time);
checkResults(rsps, 2, false);
}
示例5: callRemote
import org.jgroups.util.RspList; //导入依赖的package包/类
public void callRemote(boolean useAnycast, boolean excludeSelf) throws Exception {
// we need to copy the vector, otherwise the modification below will throw an exception because the underlying
// vector is unmodifiable
List<Address> v=new ArrayList<>(c.getView().getMembers());
if(excludeSelf) v.remove(c.getAddress());
RspList rsps=d.callRemoteMethods(v, "doSomething", new Object[]{}, new Class[]{}, new RequestOptions(ResponseMode.GET_ALL, 20000, useAnycast));
Map.Entry entry;
for(Iterator it=rsps.entrySet().iterator(); it.hasNext();) {
entry=(Map.Entry)it.next();
Address member=(Address)entry.getKey();
Rsp rsp=(Rsp)entry.getValue();
if(!rsp.wasReceived())
throw new RuntimeException("response from " + member + " was not received, rsp=" + rsp);
}
}
示例6: testOneChannel
import org.jgroups.util.RspList; //导入依赖的package包/类
/**
* Tests the deadlock resolution using self-calls on a single channel. The deadlock detection
* is turned on so the method call should go straight through. If there is a problem, JUnit will
* timeout.
*
* @throws Exception
*/
public void testOneChannel() throws Exception {
c1 = createChannel(true);
ServerObject serverObject = new ServerObject("obj1");
RpcDispatcher disp=new RpcDispatcher(c1, serverObject);
serverObject.setRpcDispatcher(disp);
c1.connect(name);
Address localAddress = c1.getAddress();
// call the nested group method on itself
MethodCall call = new MethodCall("outerMethod", new Object[0], new Class[0]);
log("calling outerMethod() on all members");
RspList rspList = disp.callRemoteMethods(null, call, new RequestOptions(ResponseMode.GET_ALL, 0));
log("results of outerMethod(): " + rspList);
Assert.assertEquals(1, rspList.size());
assertEquals("outerMethod[innerMethod]", rspList.getValue(localAddress));
assertTrue(rspList.isReceived(localAddress));
assertFalse(rspList.isSuspected(localAddress));
}
示例7: testTwoChannelsWithInitialMulticast
import org.jgroups.util.RspList; //导入依赖的package包/类
public void testTwoChannelsWithInitialMulticast() throws Exception {
ServerObject obj1, obj2 = null;
c1 = createChannel(true);
obj1 = new ServerObject("obj1");
RpcDispatcher disp1=new RpcDispatcher(c1, obj1);
obj1.setRpcDispatcher(disp1);
c1.connect(name);
c2 = createChannel(c1);
obj2 = new ServerObject("obj2");
RpcDispatcher disp2=new RpcDispatcher(c2, obj2);
obj2.setRpcDispatcher(disp2);
c2.connect(name);
Vector<Address> dests=new Vector<>();
dests.add(c1.getAddress());
dests.add(c2.getAddress());
// call a point-to-point method on Member 2 that triggers a nested distributed RPC
MethodCall call = new MethodCall("outerMethod", new Object[0], new Class[0]);
log("calling outerMethod() on all members");
RspList rsps = disp1.callRemoteMethods(dests, call, new RequestOptions(ResponseMode.GET_ALL, 0));
log("results of outerMethod():\n" + rsps);
Assert.assertEquals(2, rsps.size());
}
示例8: outerMethod
import org.jgroups.util.RspList; //导入依赖的package包/类
public String outerMethod() throws Exception {
log("**** outerMethod() received, calling innerMethod() on all members");
MethodCall call = new MethodCall("innerMethod", new Object[0], new Class[0]);
// RspList rspList = disp.callRemoteMethods(null, call, GroupResponseMode.GET_ALL, 5000);
RequestOptions opts=new RequestOptions(ResponseMode.GET_ALL, 0, false, null, (Message.Flag[])null);
opts.setFlags(Message.Flag.OOB);
RspList<String> rspList = disp.callRemoteMethods(null, call, opts);
List<String> results = rspList.getResults();
log("results of calling innerMethod():\n" + rspList);
StringBuilder sb=new StringBuilder("outerMethod[");
boolean first=true;
for(String s: results) {
if(first)
first=false;
else
sb.append(";");
sb.append(s);
}
sb.append("]");
return sb.toString();
}
示例9: testAcceptLastResponseFilter
import org.jgroups.util.RspList; //导入依赖的package包/类
/**
* Runs with response mode of GET_FIRST and the response filter accepts only the last response
* @throws Exception
*/
public void testAcceptLastResponseFilter() throws Exception {
RequestOptions options=new RequestOptions(ResponseMode.GET_FIRST, 10000, false,
new RspFilter() {
int count=0;
public boolean isAcceptable(Object response, Address sender) {
return ++count >= 3;
}
public boolean needMoreResponses() {return count < 3;}
});
RspList rsps=disp1.callRemoteMethods(null, "foo", null, null, options);
System.out.println("responses are:\n" + rsps);
Util.assertEquals("there should be three response values", 3, rsps.size());
Util.assertEquals("number of responses received should be 3", 1, rsps.numReceived());
}
示例10: setUp
import org.jgroups.util.RspList; //导入依赖的package包/类
@BeforeMethod
void setUp() throws Exception {
rl=new RspList();
a1=Util.createRandomAddress();
a2=Util.createRandomAddress();
a3=Util.createRandomAddress();
a4=Util.createRandomAddress();
a5=Util.createRandomAddress();
rsp1=new Rsp(a1);
rsp2=new Rsp(a2);
rsp2.setSuspected();
rsp3=new Rsp(a3, "hello world");
rsp4=new Rsp(a4, Boolean.TRUE);
rsp5=new Rsp(a5);
rsp5.setSuspected();
rl.put(a1, rsp1);
rl.put(a2, rsp2);
rl.put(a3, rsp3);
rl.put(a4, rsp4);
rl.put(a5, rsp5);
}
示例11: remoteExecute
import org.jgroups.util.RspList; //导入依赖的package包/类
@Override
public <T> T remoteExecute(MethodCall action, long timeout) {
logTrace(() -> String.format("RemoteExecute sync action %s with timeout %s", action, timeout));
RequestOptions options = new RequestOptions()
.setFlags(JGROUPS_FLAGS)
.setMode(ResponseMode.GET_ALL)
.setTimeout(timeout);
try {
NotifyingFuture<RspList<T>> notifyingFuture = this.<T>execute(action, options);
RspList<T> rspList = notifyingFuture.get(timeout, TimeUnit.MILLISECONDS);
return futureDone(rspList);
} catch (Exception e) {
throw new VertxException(e);
}
}
示例12: futureDone
import org.jgroups.util.RspList; //导入依赖的package包/类
private <T> T futureDone(RspList<T> rspList) {
Collection<Rsp<T>> values = rspList.values();
values.parallelStream()
.filter(Rsp::hasException)
.forEach(rsp -> logWarn(() -> String.format("Execute method failed. Sender [%s], with exception [%s]", rsp.getSender(), rsp.getException())));
T value = values.stream()
.filter(Rsp::wasReceived)
.filter(((Predicate<Rsp<T>>) Rsp::hasException).negate())
.filter(((Predicate<Rsp<T>>) Rsp::wasUnreachable).negate())
.map(Rsp::getValue)
.filter((t) -> t != null)
.reduce((a, b) -> a)
.orElse(null);
if (value instanceof DataHolder) {
return ((DataHolder<T>) value).unwrap();
} else {
return value;
}
}
示例13: whereIsState
import org.jgroups.util.RspList; //导入依赖的package包/类
protected Address whereIsState(Serializable stateId, long timeout) throws Exception {
if (remoteMembers.isEmpty()) {
return null;
}
RspList<Boolean> resp = this.disp.callRemoteMethods(getRemoteMembersCopy(), new MethodCall((short)(methodMap.size() - 5), new Object[]{stateId}), new RequestOptions(ResponseMode.GET_ALL, timeout));
Collection<Rsp<Boolean>> values = resp.values();
Rsp<Boolean> rsp = null;
for (Rsp<Boolean> response : values) {
if (Boolean.TRUE.equals(response.getValue())) {
rsp = response;
break;
}
}
if (rsp == null) {
return null;
}
return rsp.getSender();
}
示例14: throwWorkExceptionIfHasExption
import org.jgroups.util.RspList; //导入依赖的package包/类
private void throwWorkExceptionIfHasExption(RspList<ResponseValues> rspList) throws WorkException
{
if (rspList != null && rspList.getFirst() != null)
{
for (Rsp<ResponseValues> rsp : rspList)
{
if (rsp.hasException())
{
Throwable t = rsp.getException();
if (t instanceof WorkException)
{
throw (WorkException)t;
}
else
{
WorkException we = new WorkException(rsp.getException().getMessage());
we.initCause(rsp.getException());
throw we;
}
}
}
}
}
示例15: getSolvers
import org.jgroups.util.RspList; //导入依赖的package包/类
@Override
public Set<String> getSolvers() {
Set<String> solvers = new HashSet<String>(iContainer.getSolvers());
try {
RspList<Set<String>> ret = iContainer.getDispatcher().callRemoteMethods(null, "getSolvers", new Object[] {}, new Class[] {}, SolverServerImplementation.sAllResponses);
for (Rsp<Set<String>> rsp : ret) {
if (rsp != null && rsp.getValue() != null)
solvers.addAll(rsp.getValue());
}
} catch (Exception e) {
sLog.error("Failed to retrieve solvers: " + e.getMessage(), e);
}
return solvers;
}