本文整理汇总了Java中org.jgroups.stack.Protocol类的典型用法代码示例。如果您正苦于以下问题:Java Protocol类的具体用法?Java Protocol怎么用?Java Protocol使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Protocol类属于org.jgroups.stack包,在下文中一共展示了Protocol类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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;
}
示例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));
}
示例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));
}
示例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;
}
示例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);
}
示例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) {
}
}
示例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 "" ;
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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) {
}
}
示例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);
}