/** * Init JWhiteBoard interface * * @throws Exception */ public void go() throws Exception { if (!noChannel && !useState) channel.connect(groupName); mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); drawPanel = new DrawPanel(useState); drawPanel.setBackground(backgroundColor); subPanel = new JPanel(); mainFrame.getContentPane().add("Center", drawPanel); clearButton = new JButton("Clean"); clearButton.setFont(defaultFont); clearButton.addActionListener(this); leaveButton = new JButton("Exit"); leaveButton.setFont(defaultFont); leaveButton.addActionListener(this); subPanel.add("South", clearButton); subPanel.add("South", leaveButton); mainFrame.getContentPane().add("South", subPanel); mainFrame.setBackground(backgroundColor); clearButton.setForeground(Color.blue); leaveButton.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); if (!noChannel && useState) { channel.connect(groupName, null, stateTimeout); } mainFrame.setVisible(true); }
/** Tests A.startFlush(), followed by another A.startFlush() */ public void testTwoStartFlushesOnDifferentMembersWithTotalFlush() throws Exception { c1 = createChannel(true, 3); c1.connect("testTwoStartFlushesOnDifferentMembersWithTotalFlush"); c2 = createChannel(c1); c2.connect("testTwoStartFlushesOnDifferentMembersWithTotalFlush"); assertViewsReceived(c1, c2); boolean rc = startFlush(c1, false); assert rc; rc = startFlush(c2, 1, 500, false); assert !rc; stopFlush(c1); rc = startFlush(c2, false); assert rc; stopFlush(c2); rc = startFlush(c1, false); assert rc; stopFlush(c2); // c2 can actually stop a flush started by c1 rc = startFlush(c2, true); assert rc; }
public void testFlushWithCrashedParticipants() throws Exception { JChannel c1 = null; JChannel c2 = null; JChannel c3 = null; try { c1 = createChannel(true, 3, "C1"); changeProps(c1); c1.connect("testFlushWithCrashedFlushCoordinator"); c2 = createChannel(c1, "C2"); changeProps(c2); c2.connect("testFlushWithCrashedFlushCoordinator"); c3 = createChannel(c1, "C3"); changeProps(c3); c3.connect("testFlushWithCrashedFlushCoordinator"); // and then kill members other than flush coordinator Util.shutdown(c3); Util.shutdown(c1); // start flush Util.startFlush(c2); c2.stopFlush(); Util.waitUntilAllChannelsHaveSameSize(10000, 500, c2); // cluster should not hang and one remaining member should have a correct view assertTrue("correct view size", c2.getView().size() == 1); } finally { Util.close(c3, c2, c1); } }
public void testSASLDigestMD5() throws Exception { a = createChannel("A", "DIGEST-MD5", "jack"); b = createChannel("B", "DIGEST-MD5", "jack"); a.connect("SaslTest"); b.connect("SaslTest"); assertTrue(b.isConnected()); }
public void setUp() throws Exception { super.setUp(); ch1 = new JChannel(props); ch1.connect(GROUP); ch2 = new JChannel(props); ch2.connect(GROUP); }
@BeforeMethod void init() throws Exception { a = createChannel(true, 2, "A"); b = createChannel(a, "B"); setOOBPoolSize(a, b); setStableGossip(a, b); a.connect("OOBTest"); b.connect("OOBTest"); Util.waitUntilAllChannelsHaveSameSize(10000, 1000, a, b); }
/** * Multiple threads (NUM_THREADS) send messages (NUM_MSGS) * * @throws Exception */ @Test(dataProvider = "provider") public void testMessageReceptionUnderHighLoad(String props) throws Exception { CountDownLatch latch = new CountDownLatch(1); c1 = new JChannel(props); c2 = new JChannel(props); MyReceiver r1 = new MyReceiver("c1"), r2 = new MyReceiver("c2"); c1.setReceiver(r1); c2.setReceiver(r2); c1.connect("testSimpleMessageReception"); c2.connect("testSimpleMessageReception"); Address c1_addr = c1.getAddress(), c2_addr = c2.getAddress(); MySender[] c1_senders = new MySender[NUM_THREADS]; for (int i = 0; i < c1_senders.length; i++) { c1_senders[i] = new MySender(c1, c2_addr, latch); c1_senders[i].start(); } MySender[] c2_senders = new MySender[NUM_THREADS]; for (int i = 0; i < c2_senders.length; i++) { c2_senders[i] = new MySender(c2, c1_addr, latch); c2_senders[i].start(); } Util.sleep(500); latch.countDown(); // starts all threads long NUM_EXPECTED_MSGS = NUM_THREADS * NUM_MSGS; for (int i = 0; i < 20; i++) { if (r1.getNum() == NUM_EXPECTED_MSGS && r2.getNum() == NUM_EXPECTED_MSGS) break; Util.sleep(2000); UNICAST2 unicast2 = (UNICAST2) c1.getProtocolStack().findProtocol(UNICAST2.class); if (unicast2 != null) unicast2.sendStableMessages(); unicast2 = (UNICAST2) c2.getProtocolStack().findProtocol(UNICAST2.class); if (unicast2 != null) unicast2.sendStableMessages(); } System.out.println( "c1 received " + r1.getNum() + " msgs, " + getNumberOfRetransmissions(c1) + " retransmissions"); System.out.println( "c2 received " + r2.getNum() + " msgs, " + getNumberOfRetransmissions(c2) + " retransmissions"); assert r1.getNum() == NUM_EXPECTED_MSGS : "expected " + NUM_EXPECTED_MSGS + ", but got " + r1.getNum(); assert r2.getNum() == NUM_EXPECTED_MSGS : "expected " + NUM_EXPECTED_MSGS + ", but got " + r2.getNum(); }
@Test(expectedExceptions = SecurityException.class) public void testSASLDigestMD5Failure() throws Throwable { a = createChannel("A", "DIGEST-MD5", "jack"); b = createChannel("B", "DIGEST-MD5", "jill"); a.connect("SaslTest"); try { b.connect("SaslTest"); } catch (Exception e) { if (e.getCause() != null) throw e.getCause(); } }
@BeforeMethod void init() throws Exception { a = createChannel(true, 2); a.setName("A"); b = createChannel(a); b.setName("B"); setOOBPoolSize(a, b); setStableGossip(a, b); a.connect("OOBTest"); b.connect("OOBTest"); View view = b.getView(); System.out.println("view = " + view); Util.waitUntilAllChannelsHaveSameSize(20000, 1000, a, b); }
@BeforeMethod public void init() throws Exception { c1 = createChannel(true, 2); c1.setName("C1"); c2 = createChannel(c1); c2.setName("C2"); setOOBPoolSize(c1, c2); setStableGossip(c1, c2); c1.connect("OOBTest"); c2.connect("OOBTest"); View view = c2.getView(); log.info("view = " + view); Util.waitUntilAllChannelsHaveSameSize(20000, 1000, c1, c2); }
@BeforeMethod public void init() throws Exception { c1 = createChannel(true, 2); c1.setName("C1"); c2 = createChannel(c1); c2.setName("C2"); setOOBPoolSize(c1, c2); setStableGossip(c1, c2); c1.connect("OOBTest"); c2.connect("OOBTest"); View view = c2.getView(); log.info("view = " + view); assert view.size() == 2 : "view is " + view; }
@BeforeMethod void setUp() throws Exception { System.out.print("Connecting channels: "); a = createChannel("A"); disp_a = new MessageDispatcher(a, null, null); a.connect(RpcLockingTest.class.getSimpleName()); lock_a = new LockService(a).getLock("lock"); b = createChannel("B"); disp_b = new MessageDispatcher(b, null, null); b.connect(RpcLockingTest.class.getSimpleName()); lock_b = new LockService(b).getLock("lock"); Util.waitUntilAllChannelsHaveSameSize(30000, 1000, a, b); System.out.println(""); disp_a.setRequestHandler( new RequestHandler() { @Override public Object handle(Message arg0) throws Exception { System.out.println("A received a message, will now try to lock the lock"); if (lock_a.tryLock()) { Assert.fail("Should not be able to lock the lock here"); System.out.println("A aquired the lock, this shouldn't be possible"); } else System.out.println("The lock was already locked, as it should be"); return "Hello"; } }); disp_b.setRequestHandler( new RequestHandler() { @Override public Object handle(Message arg0) throws Exception { System.out.println("B received a message, will now try to lock the lock"); if (lock_b.tryLock()) { Assert.fail("Should not be able to lock the lock here"); System.out.println("B aquired the lock, this shouldn't be possible"); } else System.out.println("The lock already was locked, as it should be"); return "Hello"; } }); // Print who is the coordinator if (b.getView().getMembers().get(0).equals(b.getAddress())) System.out.println("B is the coordinator"); else System.out.println("A is the coordinator"); System.out.println(""); }
/** * Connects this member to the cluster using the given <code>loadFactor</code>. The <code> * loadFactor</code> defines the (approximate) relative load that this member will receive. * * <p>A good default value is 100, which will give this member 100 nodes on the distributed hash * ring. Giving all members (proportionally) lower values will result in a less evenly distributed * hash. * * @param loadFactor The load factor for this node. * @throws ConnectionFailedException when an error occurs while connecting */ public synchronized void connect(int loadFactor) throws ConnectionFailedException { this.currentLoadFactor = loadFactor; Assert.isTrue(loadFactor >= 0, "Load Factor must be a positive integer value."); Assert.isTrue( channel.getReceiver() == null || channel.getReceiver() == messageReceiver, "The given channel already has a receiver configured. " + "Has the channel been reused with other Connectors?"); try { channel.setReceiver(messageReceiver); if (channel.isConnected() && !clusterName.equals(channel.getClusterName())) { throw new AxonConfigurationException( "The Channel that has been configured with this JGroupsConnector " + "is already connected to another cluster."); } else if (channel.isConnected()) { // we need to fetch state now that we have attached our MessageReceiver channel.getState(null, 10000); } else { // we need to connect. This will automatically fetch state as well. channel.connect(clusterName, null, 10000); } updateMembership(); } catch (Exception e) { joinedCondition.markJoined(false); channel.disconnect(); throw new ConnectionFailedException("Failed to connect to JGroupsConnectorFactoryBean", e); } }
/** Tests the case where we don't add any fork-stack specific protocols */ public void testNullForkStack() throws Exception { fc1 = new ForkChannel(ch, "stack", "fc1"); fc2 = new ForkChannel(ch, "stack", "fc2"); MyReceiver<Integer> r1 = new MyReceiver<>(), r2 = new MyReceiver<>(); fc1.setReceiver(r1); fc2.setReceiver(r2); ch.connect(CLUSTER); fc1.connect("foo"); fc2.connect("bar"); for (int i = 1; i <= 5; i++) { fc1.send(null, i); fc2.send(null, i + 5); } List<Integer> l1 = r1.list(), l2 = r2.list(); for (int i = 0; i < 20; i++) { if (l1.size() == 5 && l2.size() == 5) break; Util.sleep(500); } System.out.println("r1: " + r1.list() + ", r2: " + r2.list()); assert r1.size() == 5 && r2.size() == 5; for (int i = 1; i <= 5; i++) assert r1.list().contains(i) && r2.list().contains(i + 5); }
private void sendMessage() { try { /** * 参数里指定Channel使用的协议栈,如果是空的,则使用默认的协议栈, 位于JGroups包里的udp.xml。参数可以是一个以冒号分隔的字符串, * 或是一个XML文件,在XML文件里定义协议栈。 */ logger.warn("发送监控同步数据通知"); Properties prop = SystemPropertiesUtils.getProp(); String hostName = NetUtils.getLocalHost(); prop.put("node.ip", NetUtils.getIpByHost(hostName)); prop.put("node.host", hostName); prop.put("install.path", getInstallPath()); // 创建一个通道 JChannel channel = new JChannel(); // 加入一个群 channel.connect("MonitorContainer"); // 发送事件 // 这里的Message的第一个参数是发送端地址 // 第二个是接收端地址 // 第三个是发送的字符串 // 具体参见jgroup send API Message msg = new Message(null, null, prop); // 发送 channel.send(msg); // 关闭通道 channel.close(); } catch (Exception e) { logger.error(e.getMessage()); } }
public static void main(String[] args) throws Exception { JChannel channel = new JChannel(); channel.setReceiver( new ReceiverAdapter() { public void receive(Message msg) { Address sender = msg.getSrc(); System.out.println(msg.getObject() + " [" + sender + "]"); } public void viewAccepted(View view) { System.out.println("view: " + view); } }); channel.connect("ChatCluster"); System.out.println( channel.getView().getCreator().equals(channel.getView().getMembers().get(0))); for (; ; ) { String line = Util.readStringFromStdin(": "); channel.send(null, line); } }
public void start(HTableIndexCoprocessor idxCoprocessor) throws Exception { this.idxCoprocessor = idxCoprocessor; loadConfiguration(); channel = new JChannel(ClassLoader.getSystemResource("tcp.xml")); channel.setReceiver(this); channel.connect("MasterIndexUpdateCluster"); }
protected JChannel createChannel(String name, boolean connect) throws Exception { JChannel retval = new JChannel( new SHARED_LOOPBACK(), new SHARED_LOOPBACK_PING(), new MERGE3() .setValue("min_interval", 3000) .setValue("max_interval", 4000) .setValue("check_interval", 7000), new NAKACK2() .setValue("use_mcast_xmit", false) .setValue("log_discard_msgs", false) .setValue("log_not_found_msgs", false), new UNICAST3(), new STABLE().setValue("max_bytes", 50000), new GMS() .setValue("print_local_addr", false) .setValue("use_merger2", true) .setValue("join_timeout", 100) .setValue("leave_timeout", 100) .setValue("merge_timeout", 5000) .setValue("log_view_warnings", false) .setValue("view_ack_collection_timeout", 50) .setValue("log_collect_msgs", false)) .name(name); if (connect) retval.connect("MergeTest4"); return retval; }
@Override public void run() { try { log.info("Hello from Cluster microservice provider!"); channel = new JChannel((String) context.getProperties().get(CLUSTER_CONFIGURATION)); channel.setReceiver(receiver); channel.connect((String) context.getProperties().get(CLUSTER_GROUP)); channel.send(new Message(null, "Holáryjou!")); try { while (!Thread.currentThread().isInterrupted()) { Thread.sleep(1000); } } catch (InterruptedException ie) { Utils.shutdownLog(log, ie); } finally { channel.close(); } } catch (Exception e) { log.error("Cluster microservice provider failed: ", e); } }
private void sendMessageToBothChannels(int size) throws Exception { long start, stop; d1.setRequestHandler(new MyHandler(new byte[size])); c2 = createChannel(c1); c2.setName("B"); disableBundling(c2); d2 = new MessageDispatcher(c2, null, null, new MyHandler(new byte[size])); c2.connect("MessageDispatcherUnitTest"); Assert.assertEquals(2, c2.getView().size()); System.out.println("casting message"); start = System.currentTimeMillis(); RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0)); stop = System.currentTimeMillis(); System.out.println("rsps:\n" + rsps); System.out.println("call took " + (stop - start) + " ms"); assertNotNull(rsps); Assert.assertEquals(2, rsps.size()); Rsp rsp = rsps.get(c1.getAddress()); assertNotNull(rsp); byte[] ret = (byte[]) rsp.getValue(); Assert.assertEquals(size, ret.length); rsp = rsps.get(c2.getAddress()); assertNotNull(rsp); ret = (byte[]) rsp.getValue(); Assert.assertEquals(size, ret.length); Util.close(c2); }
public void testNullMessageToAll() throws Exception { d1.setRequestHandler(new MyHandler(null)); c2 = createChannel(c1); c2.setName("B"); disableBundling(c2); long stop, start = System.currentTimeMillis(); d2 = new MessageDispatcher(c2, null, null, new MyHandler(null)); stop = System.currentTimeMillis(); c2.connect("MessageDispatcherUnitTest"); Assert.assertEquals(2, c2.getView().size()); System.out.println("view: " + c2.getView()); System.out.println("casting message"); start = System.currentTimeMillis(); RspList rsps = d1.castMessage(null, new Message(), new RequestOptions(ResponseMode.GET_ALL, 0)); stop = System.currentTimeMillis(); System.out.println("rsps:\n" + rsps); System.out.println("call took " + (stop - start) + " ms"); assertNotNull(rsps); Assert.assertEquals(2, rsps.size()); Rsp rsp = rsps.get(c1.getAddress()); assertNotNull(rsp); Object ret = rsp.getValue(); assert ret == null; rsp = rsps.get(c2.getAddress()); assertNotNull(rsp); ret = rsp.getValue(); assert ret == null; Util.close(c2); }
/** * 启动连接。 * * @throws Exception */ private void start() throws Exception { channle = new JChannel(); channle.setReceiver(this); channle.connect("ChatCluster"); channle.getState(null, 10000); eventloop(); channle.close(); }
public void testSASLDigestMD5Merge() throws Exception { a = createChannel("A", "DIGEST-MD5", "jack"); b = createChannel("B", "DIGEST-MD5", "jack"); a.connect("SaslTest"); b.connect("SaslTest"); assertTrue(b.isConnected()); print(a, b); createPartitions(a, b); print(a, b); assertTrue(checkViewSize(1, a, b)); dropDiscard(a, b); mergePartitions(a, b); for (int i = 0; i < 10 && !checkViewSize(2, a, b); i++) { Util.sleep(500); } assertTrue(viewContains(a.getView(), a, b)); assertTrue(viewContains(b.getView(), a, b)); }
public void run() { try { ch = new JChannel(props); changeProperties(ch); barrier.await(); // wait for all threads to be running ch.connect(groupname); } catch (Exception e) { } }
@BeforeMethod void start() throws Exception { r1 = new MyReceiver("A"); r2 = new MyReceiver("B"); a = new JChannel(props); a.setName("A"); a.connect(CLUSTER); a_addr = a.getAddress(); a.setReceiver(r1); u1 = a.getProtocolStack().findProtocol(UNICAST.class); b = new JChannel(props); b.setName("B"); b.connect(CLUSTER); b_addr = b.getAddress(); b.setReceiver(r2); u2 = b.getProtocolStack().findProtocol(UNICAST.class); System.out.println("A=" + a_addr + ", B=" + b_addr); }
@BeforeClass protected void setUp() throws Exception { c1 = createChannel(true); c1.setName("A"); GMS gms = (GMS) c1.getProtocolStack().findProtocol(GMS.class); if (gms != null) gms.setPrintLocalAddress(false); disableBundling(c1); d1 = new MessageDispatcher(c1, null, null, null); c1.connect("MessageDispatcherUnitTest"); }
/** Tests https://issues.jboss.org/browse/JGRP-1369 */ public void testRequestOptionsChaining() throws Exception { MuxRpcDispatcher muxRpc = new MuxRpcDispatcher((short) 1, channel, null, null, new Server()); channel.connect("group"); for (int i = 0; i < 20; i++) muxRpc.callRemoteMethods(null, new MethodCall(Server.class.getMethod("foo")), reqOpt); RspFilter filter = reqOpt.getRspFilter(); int count = count(filter); System.out.println("count=" + count); assert count == 1; }
private void createChannels( boolean copy_multicasts, boolean copy_unicasts, int num_outgoing_copies, int num_incoming_copies) throws Exception { c1 = createChannel(true, 3); DUPL dupl = new DUPL(copy_multicasts, copy_unicasts, num_incoming_copies, num_outgoing_copies); ProtocolStack stack = c1.getProtocolStack(); stack.insertProtocol(dupl, ProtocolStack.BELOW, NAKACK.class); c2 = createChannel(c1); c3 = createChannel(c1); c1.connect("DuplicateTest"); c2.connect("DuplicateTest"); c3.connect("DuplicateTest"); Util.waitUntilAllChannelsHaveSameSize(20000, 1000, c1, c2, c3); }
public void testFlushWithCrashedFlushCoordinator() throws Exception { JChannel a = null, b = null, c = null; try { a = createChannel(true, 3, "A"); changeProps(a); a.connect("testFlushWithCrashedFlushCoordinator"); b = createChannel(a, "B"); changeProps(b); b.connect("testFlushWithCrashedFlushCoordinator"); c = createChannel(a, "C"); changeProps(c); c.connect("testFlushWithCrashedFlushCoordinator"); System.out.println("shutting down flush coordinator B"); b.down(new Event(Event.SUSPEND_BUT_FAIL)); // send out START_FLUSH and then return // now shut down B. This means, after failure detection kicks in and the new coordinator takes // over // (either A or C), that the current flush started by B will be cancelled and a new flush (by // A or C) // will be started Util.shutdown(b); a.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug"); c.getProtocolStack().findProtocol(FLUSH.class).setLevel("debug"); Util.waitUntilAllChannelsHaveSameSize(10000, 500, a, c); // cluster should not hang and two remaining members should have a correct view assertTrue("correct view size", a.getView().size() == 2); assertTrue("correct view size", c.getView().size() == 2); a.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn"); c.getProtocolStack().findProtocol(FLUSH.class).setLevel("warn"); } finally { Util.close(c, b, a); } }
/** Tests A.startFlush(), followed by another A.startFlush() */ @Test public void testTwoStartFlushesOnSameMemberWithTotalFlush() throws Exception { c1 = createChannel(true, 3); c1.connect("testTwoStartFlushes"); c2 = createChannel(c1); c2.connect("testTwoStartFlushes"); assertViewsReceived(c1, c2); boolean rc = startFlush(c1, true); assert rc; rc = startFlush(c1, false); assert rc; rc = startFlush(c1, 1, 500, false); assert !rc; stopFlush(c1); rc = startFlush(c1, true); assert rc; }