本文整理汇总了Java中org.jgroups.stack.Protocol类的典型用法代码示例。如果您正苦于以下问题:Java Protocol类的具体用法?Java Protocol怎么用?Java Protocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Protocol类属于org.jgroups.stack包,在下文中一共展示了Protocol类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUp
import org.jgroups.stack.Protocol; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
stats = new MyStats();
// create a StatRecorder that has mock up/down protocols and stats
mockDownProtocol = mock(Protocol.class);
mockUpProtocol = mock(Protocol.class);
services = mock(Services.class);
when(services.getStatistics()).thenReturn(stats);
recorder = new StatRecorder();
recorder.setServices(services);
recorder.setUpProtocol(mockUpProtocol);
recorder.setDownProtocol(mockDownProtocol);
}
开发者ID:ampool,项目名称:monarch,代码行数:17,代码来源:StatRecorderJUnitTest.java
示例2: ForkChannel
import org.jgroups.stack.Protocol; //导入依赖的package包/类
/**
* Creates a new fork-channel from a main-channel. The channel is unconnected and {@link ForkChannel#connect(String)}
* needs to be called to send and receive messages.
* @param main_channel The main-channel. The lifetime of the newly created channel will be less than or equal to
* the main-channel
* @param fork_stack_id The ID to associate the fork-stack with in FORK
* @param fork_channel_id The ID used to map fork-channel IDs to ForkChannels in the fork-channels protocol stack
* @param create_fork_if_absent If true, and FORK doesn't exist, a new FORK protocol will be created and inserted
* into the main-stack at the given position. If false, and FORK doesn't exist, an
* exception will be thrown
* @param position The position at which the newly created FORK will be inserted. {@link ProtocolStack#ABOVE} or
* {@link ProtocolStack#BELOW} are accepted. Ignored if create_fork_if_absent is false.
* @param neighbor The class of the neighbor protocol below or above which the newly created FORK protocol will
* be inserted. Ignored if create_fork_if_absent is false.
* @param protocols A list of protocols (<em>from bottom to top</em> !) to insert as the fork_stack in FORK under the
* given fork_stack_id. If the fork-stack with fork_stack_id already exists, an exception will be
* thrown.
* Can be null if no protocols should be added. This may be the case when an app only wants to use
* a ForkChannel to mux/demux messages, but doesn't need a different protocol stack.
*
* @throws Exception
*/
public ForkChannel(final Channel main_channel, String fork_stack_id, String fork_channel_id,
boolean create_fork_if_absent, int position, Class<? extends Protocol> neighbor,
Protocol ... protocols) throws Exception {
super(false);
if(main_channel == null) throw new IllegalArgumentException("main channel cannot be null");
if(fork_stack_id == null) throw new IllegalArgumentException("fork_stack_id cannot be null");
if(fork_channel_id == null) throw new IllegalArgumentException("fork_channel_id cannot be null");
this.main_channel=main_channel;
this.fork_channel_id=fork_channel_id;
FORK fork;
// To prevent multiple concurrent FORK creations https://issues.jboss.org/browse/JGRP-1842
synchronized(this.main_channel) {
fork=getFORK(main_channel, position, neighbor, create_fork_if_absent);
}
// Returns the existing fork stack for fork_stack_id, or creates a new one
prot_stack=fork.createForkStack(fork_stack_id, protocols == null? null : Arrays.asList(protocols), true);
flush_supported=main_channel.flushSupported();
state=State.OPEN;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:46,代码来源:ForkChannel.java
示例3: registerChannel
import org.jgroups.stack.Protocol; //导入依赖的package包/类
/**
* Registers an already created channel with the given MBeanServer. Wraps instance of JChannel
* with DynamicMBean and delegates all calls to the actual JChannel wrapped.
* <p>
* Optionally, this method will also wrap each protocol in the given channel with DynamicMBean
* and register it as well.
*
* @param channel
* @param server
* @param domain
* Has to be a JMX ObjectName of the domain, e.g. DefaultDomain:name=JGroups
* @param register_protocols
*/
public static void registerChannel(JChannel channel, MBeanServer server, String domain,
String cluster_name, boolean register_protocols) throws Exception {
if(channel == null)
throw new NullPointerException("channel cannot be null");
if (cluster_name == null)
cluster_name=channel.getClusterName();
if (cluster_name == null)
cluster_name = "null";
cluster_name=ObjectName.quote(cluster_name);
if (register_protocols) {
ProtocolStack stack = channel.getProtocolStack();
List<Protocol> protocols = stack.getProtocols();
for (Protocol p : protocols) {
if (p.getClass().isAnnotationPresent(MBean.class)) {
String jmx_name=getProtocolRegistrationName(cluster_name,domain,p);
register(p, server, jmx_name);
}
}
}
register(channel, server, getChannelRegistrationName(channel, domain, cluster_name));
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:38,代码来源:JmxConfigurator.java
示例4: unregisterChannel
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public static void unregisterChannel(JChannel c, MBeanServer server, String domain, String clusterName)
throws Exception {
if(clusterName != null)
clusterName=ObjectName.quote(clusterName);
ProtocolStack stack = c.getProtocolStack();
List<Protocol> protocols = stack.getProtocols();
for (Protocol p : protocols) {
if (p.getClass().isAnnotationPresent(MBean.class)) {
try {
String obj_name=getProtocolRegistrationName(clusterName, domain, p);
unregister(p, server, obj_name);
} catch (MBeanRegistrationException e) {
log.warn("MBean unregistration failed: " + e.getCause());
}
}
}
unregister(c, server, getChannelRegistrationName(c, domain, clusterName));
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:JmxConfigurator.java
示例5: fetchResponsesFromDiscoveryProtocol
import org.jgroups.stack.Protocol; //导入依赖的package包/类
protected Responses fetchResponsesFromDiscoveryProtocol(List<Address> missing) {
if(!isSingleton())
return (Responses)up_prot.up(new Event(Event.FIND_MBRS, missing));
int size=missing == null? 16 : missing.size();
final Responses rsps=new Responses(size, false, size);
Collection<Protocol> prots=up_prots.values();
if(prots != null) {
for(Protocol prot: prots) {
Responses tmp_rsp=(Responses)prot.up(new Event(Event.FIND_MBRS, missing));
if(tmp_rsp != null) {
for(PingData data: tmp_rsp)
rsps.addResponse(data, true);
}
}
}
return rsps;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:TP.java
示例6: up
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public Object up(Event evt) {
switch(evt.getType()) {
case Event.MSG:
Message msg=(Message)evt.getArg();
ForkHeader hdr=(ForkHeader)msg.getHeader(id);
if(hdr == null)
break;
if(hdr.fork_stack_id == null)
throw new IllegalArgumentException("header has a null fork_stack_id");
Protocol bottom_prot=get(hdr.fork_stack_id);
return bottom_prot != null? bottom_prot.up(evt) : this.unknownForkHandler.handleUnknownForkStack(msg, hdr.fork_stack_id);
case Event.VIEW_CHANGE:
for(Protocol bottom: fork_stacks.values())
bottom.up(evt);
break;
}
return up_prot.up(evt);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:20,代码来源:FORK.java
示例7: sendMessages
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public void sendMessages(final Protocol prot, final int start, final int end) {
final Thread sender=new Thread() {
public void run() {
for(int i=start; i <= end; i++) {
Message msg=new Message(null, i);
System.out.println("[" + prot.getValue("local_addr") + "] --> sending message " + i);
prot.down(new Event(Event.MSG,msg));
}
}
};
sender.setName("BytemanSenderThread");
sender.start();
try {
sender.join(1000);
}
catch(InterruptedException e) {
}
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:SequencerFailoverTestHelper.java
示例8: convert
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public Object convert(Object obj, Class<?> propertyFieldType, String propertyName, String propertyValue, boolean check_scope) throws Exception {
// get the existing bind address - possibly null
InetAddress old_bind_addr = (InetAddress)Configurator.getValueFromProtocol((Protocol)obj, "bind_addr");
// apply a bind interface constraint
InetAddress new_bind_addr = Util.validateBindAddressFromInterface(old_bind_addr, propertyValue);
if (new_bind_addr != null)
setBindAddress((Protocol)obj, new_bind_addr) ;
// if no bind_interface specified, set it to the empty string to avoid exception
// from @Property processing
if (propertyValue != null)
return propertyValue ;
else
return "" ;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:PropertyConverters.java
示例9: createChannel
import org.jgroups.stack.Protocol; //导入依赖的package包/类
private static JChannel createChannel(String channelName,String mech,String username) throws Exception {
SASL sasl = new SASL();
sasl.setMech(mech);
sasl.setClientCallbackHandler(new MyCallbackHandler(username));
sasl.setServerCallbackHandler(new MyCallbackHandler(username));
sasl.setTimeout(5000);
sasl.sasl_props.put("com.sun.security.sasl.digest.realm", REALM);
return new JChannel(
new Protocol[] {
new SHARED_LOOPBACK(),
new PING(),
new NAKACK2(),
new UNICAST3(),
new STABLE(),
sasl,
new GMS() }
).name(channelName);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:SASLTest.java
示例10: setProps
import org.jgroups.stack.Protocol; //导入依赖的package包/类
protected static void setProps(JChannel... channels) {
for(JChannel ch: channels) {
Protocol prot=ch.getProtocolStack().findProtocol(FRAG2.class);
if(prot != null) {
((FRAG2)prot).setFragSize(12000);
}
prot=ch.getProtocolStack().findProtocol(FRAG.class);
if(prot != null) {
((FRAG)prot).setFragSize(12000);
}
prot=ch.getProtocolStack().getTransport();
if(prot != null)
((TP)prot).setMaxBundleSize(14000);
}
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:17,代码来源:RpcDispatcherTest.java
示例11: replaceStateTransferProtocolWith
import org.jgroups.stack.Protocol; //导入依赖的package包/类
protected void replaceStateTransferProtocolWith(JChannel ch, Class<?> state_transfer_class) throws Exception {
ProtocolStack stack=ch.getProtocolStack();
if(stack.findProtocol(state_transfer_class) != null)
return; // protocol of the right class is already in stack
Protocol prot=stack.findProtocol(STATE_TRANSFER.class, StreamingStateTransfer.class);
Protocol new_state_transfer_protcol=(Protocol)state_transfer_class.newInstance();
if(prot != null) {
stack.replaceProtocol(prot, new_state_transfer_protcol);
}
else { // no state transfer protocol found in stack
Protocol flush=stack.findProtocol(FLUSH.class);
if(flush != null)
stack.insertProtocol(new_state_transfer_protcol, ProtocolStack.BELOW, FLUSH.class);
else
stack.insertProtocolAtTop(new_state_transfer_protcol);
}
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:StateTransferTest2.java
示例12: create
import org.jgroups.stack.Protocol; //导入依赖的package包/类
private static JChannel[] create(boolean use_flush_props, boolean simple_ids, String cluster_name, String ... names) throws Exception {
JChannel[] retval=new JChannel[names.length];
for(int i=0; i < retval.length; i++) {
JChannel ch;
Protocol[] props=use_flush_props? getFlushProps() : getProps();
if(simple_ids) {
ch=new MyChannel(props);
((MyChannel)ch).setId(i+1);
}
else
ch=new JChannel(props);
ch.setName(names[i]);
retval[i]=ch;
ch.connect(cluster_name);
if(i == 0)
Util.sleep(3000);
}
return retval;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:GMS_MergeTest.java
示例13: modifyStack
import org.jgroups.stack.Protocol; //导入依赖的package包/类
private static void modifyStack(JChannel ch) {
ProtocolStack stack=ch.getProtocolStack();
Protocol prot=stack.findProtocol(MERGE3.class);
if(prot != null) {
MERGE3 merge=(MERGE3)prot;
merge.setMinInterval(3000);
merge.setMaxInterval(5000);
}
prot=stack.findProtocol(STABLE.class);
if(prot != null) {
STABLE stable=(STABLE)prot;
stable.setDesiredAverageGossip(5000);
}
prot=stack.findProtocol(NAKACK2.class);
if(prot != null) {
((NAKACK2)prot).setLogDiscardMessages(false);
}
prot=stack.findProtocol(FD_SOCK.class);
if(prot != null) {
((FD_SOCK)prot).setLogSuspectedMessages(false);
}
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:23,代码来源:MergeStressTest.java
示例14: sendMessages
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public void sendMessages(final Protocol prot, final int start, final int end) {
final Thread sender=new Thread() {
public void run() {
for(int i=start; i <= end; i++) {
Event evt=new Event(Event.FORWARD_TO_COORD, new Message(null, i));
System.out.println("[byteman] --> sending message " + i);
prot.down(evt);
}
}
};
sender.setName("BytemanSenderThread");
sender.start();
try {
sender.join(1000);
}
catch(InterruptedException e) {
}
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:19,代码来源:ForwardToCoordFailoverTestHelper.java
示例15: testLastMessageDropped
import org.jgroups.stack.Protocol; //导入依赖的package包/类
/**
* A sends unicast messages 1-5 to B, but we drop message 5. The code in
* https://issues.jboss.org/browse/JGRP-1548 now needs to make sure message 5 is retransmitted to B
* within a short time period, and we don't have to rely on the stable task to kick in.
*/
@Test(dataProvider="configProvider")
public void testLastMessageDropped(Class<? extends Protocol> unicast_class) throws Exception {
setup(unicast_class);
setLevel("trace", a, b);
Address dest=b.getAddress();
for(int i=1; i <= 5; i++) {
Message msg=new Message(dest, i);
if(i == 5)
discard.setDropDownUnicasts(1); // drops the next unicast
a.send(msg);
}
List<Integer> msgs=rb.list();
Util.waitUntilListHasSize(msgs, 5, 10000, 1000);
System.out.println("list=" + msgs);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:22,代码来源:UNICAST_DropFirstAndLastTest.java
示例16: testAssignmentInetAddresses
import org.jgroups.stack.Protocol; //导入依赖的package包/类
public void testAssignmentInetAddresses() throws Exception {
Vector<ProtocolConfiguration> protocol_configs = new Vector<>() ;
Vector<Protocol> protocols = new Vector<>() ;
// create the layer described by INETADDRESSES
protocol = Configurator.createProtocol(addressProps, stack) ;
// get the value which should have been assigned a default
InetAddress a = ((INETADDRESSES)protocol).getInetAddressField() ;
System.out.println("value of inetAddressField = " + a) ;
// get the value which should not have been assigned a default
InetAddress b = ((INETADDRESSES)protocol).getInetAddressMethod() ;
System.out.println("value of inetAddressMethod = " + b) ;
// get the value which should have been assigned a default
List<IpAddress> c = ((INETADDRESSES)protocol).getIpAddressListField() ;
System.out.println("value of ipAddressListField = " + c) ;
// get the value which should not have been assigned a default
List<IpAddress> d = ((INETADDRESSES)protocol).getIpAddressListMethod() ;
System.out.println("value of ipAddressListMethod = " + d) ;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:26,代码来源:ProtocolConfigurationTest.java
示例17: createChannel
import org.jgroups.stack.Protocol; //导入依赖的package包/类
protected static JChannel createChannel(Protocol unicast, DISCARD discard) throws Exception {
JChannel ch=new JChannel(false);
ProtocolStack stack=new ProtocolStack();
ch.setProtocolStack(stack);
stack.addProtocol(new SHARED_LOOPBACK());
if(discard != null)
stack.addProtocol(discard);
if(unicast instanceof UNICAST2)
unicast.setValue("stable_interval", 3000);
stack.addProtocol(new SHARED_LOOPBACK_PING())
.addProtocol(new NAKACK2().setValue("use_mcast_xmit", false))
.addProtocol(unicast)
.addProtocol(new STABLE().setValue("max_bytes", 50000))
.addProtocol(new GMS().setValue("print_local_addr", false));
stack.init();
return ch;
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:UNICAST_MessagesToSelfTest.java
示例18: testAClosingUnilaterallyButLosingFirstMessage
import org.jgroups.stack.Protocol; //导入依赖的package包/类
/**
* Scenario #6 (A closes the connection unilaterally (B keeps it open), then reopens it and sends messages,
* but loses the first message
*/
@Test(dataProvider="configProvider")
public void testAClosingUnilaterallyButLosingFirstMessage(Class<? extends Protocol> unicast) throws Exception {
setup(unicast);
sendAndCheck(a, b_addr, 10, r2);
// now close connection on A unilaterally
System.out.println("==== Closing the connection on A");
removeConnection(u1, b_addr);
// add a Drop protocol to drop the first unicast message
Drop drop=new Drop(true);
a.getProtocolStack().insertProtocol(drop, ProtocolStack.BELOW,(Class<? extends Protocol>[])Util.getUnicastProtocols());
// then send messages from A to B
sendAndCheck(a, b_addr, 10, r2);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:21,代码来源:UNICAST_ConnectionTests.java
示例19: testMessageToNonExistingMember
import org.jgroups.stack.Protocol; //导入依赖的package包/类
@Test(dataProvider="configProvider")
public void testMessageToNonExistingMember(Class<? extends Protocol> unicast) throws Exception {
Map<String,Object> props=new HashMap<>(1);
props.put("max_retransmit_time",5000);
setup(unicast,props);
Address target=Util.createRandomAddress("FakeAddress");
a.send(target, "hello");
Protocol prot=a.getProtocolStack().findProtocol(unicast);
Method hasSendConnectionTo=unicast.getMethod("hasSendConnectionTo", Address.class);
for(int i=0; i < 10; i++) {
boolean result=(Boolean)hasSendConnectionTo.invoke(prot, target);
if(!result)
break;
Util.sleep(1000);
}
assert !(Boolean)hasSendConnectionTo.invoke(prot, target);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:18,代码来源:UNICAST_ConnectionTests.java
示例20: testNotEndlessXmits
import org.jgroups.stack.Protocol; //导入依赖的package包/类
@Test(dataProvider="configProvider")
public void testNotEndlessXmits(Class<? extends Protocol> unicast_class) throws Exception {
setup(unicast_class);
DISCARD discard_a=(DISCARD)a.getProtocolStack().findProtocol(DISCARD.class);
discard_a.setDropDownUnicasts(5); // drops the next 5 ACKs
for(int i=1; i <= 5; i++)
b.send(a.getAddress(), i);
Protocol unicast_b=b.getProtocolStack().findProtocol(UNICAST.class, UNICAST3.class);
for(int i=0; i < 10; i++) {
int num_unacked_msgs=numUnackedMessages(unicast_b);
System.out.println("num_unacked_msgs=" + num_unacked_msgs);
if(num_unacked_msgs == 0)
break;
Util.sleep(1000);
}
assert numUnackedMessages(unicast_b) == 0 : "num_unacked_msgs on B should be 0 but is " + numUnackedMessages(unicast_b);
}
开发者ID:zjumty,项目名称:jgroups-3.6.4-fixed,代码行数:22,代码来源:UNICAST_DroppedAckTest.java
注:本文中的org.jgroups.stack.Protocol类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论