本文整理汇总了Java中org.jgroups.util.Tuple类的典型用法代码示例。如果您正苦于以下问题:Java Tuple类的具体用法?Java Tuple怎么用?Java Tuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tuple类属于org.jgroups.util包,在下文中一共展示了Tuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createStreamToProvider
import org.jgroups.util.Tuple; //导入依赖的package包/类
protected Tuple<InputStream,Object> createStreamToProvider(Address provider, StateHeader hdr) throws Exception {
IpAddress address=hdr.bind_addr;
Tuple<InputStream,Object> retval=new Tuple<>(null,null);
Socket socket=null;
try {
socket=getSocketFactory().createSocket("jgroups.state_sock.sock");
retval.setVal2(socket);
socket.bind(new InetSocketAddress(bind_addr, 0));
socket.setReceiveBufferSize(buffer_size);
Util.connect(socket, new InetSocketAddress(address.getIpAddress(), address.getPort()), 0);
log.debug("%s: connected to state provider %s:%d", local_addr, address.getIpAddress(), address.getPort());
DataOutputStream out=new DataOutputStream(socket.getOutputStream());
Util.writeAddress(local_addr, out);
retval.setVal1(new BufferedInputStream(socket.getInputStream(), buffer_size));
return retval;
}
catch(Throwable t) {
Util.close(socket);
if(t instanceof Exception)
throw (Exception)t;
throw new Exception("failed creating socket", t);
}
}
示例2: handleDownMessage
import org.jgroups.util.Tuple; //导入依赖的package包/类
protected Object handleDownMessage(final Event evt, final Message msg, Address dest, int length) {
if(dest != null) // 2nd line of defense, not really needed
return down_prot.down(evt);
long block_time=max_block_times != null? getMaxBlockTime(length) : max_block_time;
while(running) {
boolean rc=credits.decrement(length, block_time);
if(rc || max_block_times != null || !running)
break;
if(needToSendCreditRequest()) {
List<Tuple<Address,Long>> targets=credits.getMembersWithCreditsLessThan(min_credits);
for(Tuple<Address,Long> tuple: targets)
sendCreditRequest(tuple.getVal1(), Math.min(max_credits, max_credits - tuple.getVal2()));
}
}
// send message - either after regular processing, or after blocking (when enough credits are available again)
return down_prot.down(evt);
}
示例3: initProtocolStack
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void initProtocolStack() throws Exception {
List<Protocol> protocols = getProtocols();
Collections.reverse(protocols);
for(Protocol prot: protocols) {
if(prot.getProtocolStack() == null)
prot.setProtocolStack(this);
if(prot instanceof TP) {
TP transport=(TP)prot;
if(transport.isSingleton()) {
String singleton_name=transport.getSingletonName();
synchronized(singleton_transports) {
Tuple<TP,RefCounter> val=singleton_transports.get(singleton_name);
if(val == null)
singleton_transports.put(singleton_name, new Tuple<>(transport,new RefCounter((short)1, (short)0)));
else {
RefCounter counter=val.getVal2();
short num_inits=counter.incrementInitCount();
if(num_inits >= 1)
continue;
}
prot.init(); // if shared TP, call init() with lock : https://issues.jboss.org/browse/JGRP-1887
continue;
}
}
}
prot.init();
}
}
示例4: destroy
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void destroy() {
if(top_prot != null) {
for(Protocol prot: getProtocols()) {
if(prot instanceof TP) {
TP transport=(TP)prot;
if(transport.isSingleton()) {
String singleton_name=transport.getSingletonName();
synchronized(singleton_transports) {
Tuple<TP, ProtocolStack.RefCounter> val=singleton_transports.get(singleton_name);
if(val != null) {
ProtocolStack.RefCounter counter=val.getVal2();
short num_inits=counter.decrementInitCount();
if(num_inits >= 1) {
continue;
}
else
singleton_transports.remove(singleton_name);
}
}
}
}
prot.destroy();
}
/*
*Do not null top_prot reference since we need recreation of channel properties (JChannel#getProperties)
*during channel recreation, especially if those properties were modified after channel was created.
*We modify channel properties after channel creation in some tests for example
*
*/
//top_prot=null;
}
}
示例5: createProtocols
import org.jgroups.util.Tuple; //导入依赖的package包/类
/**
* Takes vector of ProtocolConfigurations, iterates through it, creates Protocol for
* each ProtocolConfiguration and returns all Protocols in a list.
* @param protocol_configs List of ProtocolConfigurations
* @param stack The protocol stack
* @return List of Protocols
*/
public static List<Protocol> createProtocols(List<ProtocolConfiguration> protocol_configs, final ProtocolStack stack) throws Exception {
List<Protocol> retval=new LinkedList<>();
ProtocolConfiguration protocol_config;
Protocol layer;
String singleton_name;
for(int i=0; i < protocol_configs.size(); i++) {
protocol_config=protocol_configs.get(i);
singleton_name=protocol_config.getProperties().get(Global.SINGLETON_NAME);
if(singleton_name != null && !singleton_name.trim().isEmpty()) {
Map<String,Tuple<TP, ProtocolStack.RefCounter>> singleton_transports=ProtocolStack.getSingletonTransports();
synchronized(singleton_transports) {
if(i > 0) { // crude way to check whether protocol is a transport
throw new IllegalArgumentException("Property 'singleton_name' can only be used in a transport" +
" protocol (was used in " + protocol_config.getProtocolName() + ")");
}
Tuple<TP, ProtocolStack.RefCounter> val=singleton_transports.get(singleton_name);
layer=val != null? val.getVal1() : null;
if(layer != null) {
retval.add(layer);
}
else {
layer=createLayer(stack, protocol_config);
if(layer == null)
return null;
singleton_transports.put(singleton_name, new Tuple<>((TP)layer,new ProtocolStack.RefCounter((short)0,(short)0)));
retval.add(layer);
}
}
continue;
}
layer=createLayer(stack, protocol_config);
if(layer == null)
return null;
retval.add(layer);
}
return retval;
}
示例6: checkReceivedMessages
import org.jgroups.util.Tuple; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected void checkReceivedMessages(Tuple<MyReceiver,Integer> ... expected_messages) {
for(int i=0; i < 30; i++) {
boolean all_received=true;
for(Tuple<MyReceiver,Integer> tuple: expected_messages) {
MyReceiver receiver=tuple.getVal1();
List<Message> mcasts=receiver.getMulticasts();
int mcasts_received=mcasts.size();
int expected_mcasts=tuple.getVal2();
if(mcasts_received != expected_mcasts) {
all_received=false;
break;
}
}
if(all_received)
break;
runStableProtocol(a,b,c);
Util.sleep(1000);
}
for(Tuple<MyReceiver,Integer> tuple: expected_messages) {
MyReceiver receiver=tuple.getVal1();
List<Message> mcasts=receiver.getMulticasts();
int mcasts_received=mcasts.size();
System.out.println("receiver " + receiver + ": mcasts=" + mcasts_received);
}
for(Tuple<MyReceiver,Integer> tuple: expected_messages) {
MyReceiver receiver=tuple.getVal1();
List<Message> mcasts=receiver.getMulticasts();
int mcasts_received=mcasts.size();
int expected_mcasts=tuple.getVal2();
assert mcasts_received == expected_mcasts : "(" + receiver.name + ") num_mcasts=" + print(mcasts) +
" expected: " + expected_mcasts + ")";
}
}
示例7: testRegularUnicastsToOthers
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void testRegularUnicastsToOthers() throws Exception {
send(a, b.getAddress(), false, 10);
send(a, c.getAddress(), false, 10);
sendStableMessages(a,b,c);
check(r2, 1, false, new Tuple<>(a1, 10));
check(r3, 1, false, new Tuple<>(a1, 10));
}
示例8: testOOBUnicastsToOthers
import org.jgroups.util.Tuple; //导入依赖的package包/类
@Test(invocationCount=10)
public void testOOBUnicastsToOthers() throws Exception {
send(a, b.getAddress(), true, 10);
send(a, c.getAddress(), true, 10);
sendStableMessages(a,b,c);
check(r2, 1, true, new Tuple<>(a1, 10));
check(r3, 1, true, new Tuple<>(a1, 10));
}
示例9: testRegularMulticastToAll
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void testRegularMulticastToAll() throws Exception {
send(a, null /** multicast */, false, 10);
sendStableMessages(a,b,c);
check(r1, 1, false, new Tuple<>(a1, 10));
check(r2, 1, false, new Tuple<>(a1, 10));
check(r3, 1, false, new Tuple<>(a1, 10));
}
示例10: testOOBMulticastToAll
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void testOOBMulticastToAll() throws Exception {
send(a, null /** multicast */, true, 10);
sendStableMessages(a,b,c);
check(r1,1,true,new Tuple<>(a1,10));
check(r2, 1, true, new Tuple<>(a1, 10));
check(r3, 1, true, new Tuple<>(a1, 10));
}
示例11: testRegularMulticastToAll3Senders
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void testRegularMulticastToAll3Senders() throws Exception {
send(a, null /** multicast */, false, 10);
send(b, null /** multicast */, false, 10);
send(c, null /** multicast */, false, 10);
sendStableMessages(a,b,c);
check(r1, 3, false, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r2, 3, false, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r3, 3, false, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
}
示例12: testOOBMulticastToAll3Senders
import org.jgroups.util.Tuple; //导入依赖的package包/类
@Test(invocationCount=5)
public void testOOBMulticastToAll3Senders() throws Exception {
send(a, null /** multicast */, true, 10);
send(b, null /** multicast */, true, 10);
send(c, null /** multicast */, true, 10);
sendStableMessages(a,b,c);
check(r1, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r2, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r3, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
}
示例13: testMixedMulticastsToAll3Members
import org.jgroups.util.Tuple; //导入依赖的package包/类
public void testMixedMulticastsToAll3Members() throws Exception {
send(a, null /** multicast */, false, true, 10);
send(b, null /** multicast */, false, true, 10);
send(c, null /** multicast */, false, true, 10);
sendStableMessages(a,b,c);
check(r1, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r2, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
check(r3, 3, true, new Tuple<>(a1, 10), new Tuple<>(a2, 10), new Tuple<>(a3, 10));
}
示例14: check
import org.jgroups.util.Tuple; //导入依赖的package包/类
private void check(MyReceiver receiver, int expected_size, boolean oob, Tuple<Address,Integer>... vals) {
Map<Address, Collection<Long>> msgs=receiver.getMsgs();
for(int i=0; i < 10; i++) {
if(msgs.size() >= expected_size)
break;
Util.sleep(1000);
}
assert msgs.size() == expected_size : "expected size=" + expected_size + ", msgs: " + msgs.keySet();
for(Tuple<Address,Integer> tuple: vals) {
Address addr=tuple.getVal1();
Collection<Long> list=msgs.get(addr);
assert list != null : "no list available for " + addr;
int expected_values=tuple.getVal2();
for(int i=0; i < 20; i++) {
if(list.size() >= expected_values)
break;
Util.sleep(1000);
sendStableMessages(a,b,c);
}
System.out.println("[" + receiver.getName() + "]: " + addr + ": " + list);
assert list.size() == expected_values : addr + "'s list's size is not " + tuple.getVal2() +
", list: " + list + " (size=" + list.size() + ")";
if(!oob) // if OOB messages, ordering is not guaranteed
check(addr, list);
else
checkPresence(list);
}
}
示例15: testSet
import org.jgroups.util.Tuple; //导入依赖的package包/类
public static void testSet() {
Tuple<String,Integer> tuple=new Tuple<>("Bela", 322649);
System.out.println("tuple: " + tuple);
tuple.setVal1("Michelle");
tuple.setVal2(7);
Assert.assertEquals("Michelle", tuple.getVal1());
Assert.assertEquals(7, tuple.getVal2().intValue());
}