Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ppp.network;
- import java.io.Closeable;
- import java.io.IOException;
- import java.util.logging.Logger;
- import org.jgroups.JChannel;
- import org.jgroups.ReceiverAdapter;
- import org.jgroups.View;
- import org.jgroups.blocks.MethodCall;
- import org.jgroups.blocks.RequestOptions;
- import org.jgroups.blocks.ResponseMode;
- import org.jgroups.blocks.RpcDispatcher;
- import org.jgroups.fork.ForkChannel;
- import org.jgroups.protocols.FORK;
- public class JChannelRunner extends ReceiverAdapter implements Closeable {
- public static class Boe1 {
- public void boeee() {
- LOGGER.info("boe-1");
- }
- }
- private final static Logger LOGGER = Logger.getLogger(JChannelRunner.class.getName());
- JChannel channel;
- ForkChannel forkChannel;
- RpcDispatcher dispatcher1;
- public JChannelRunner() throws Exception {
- channel = new JChannel();
- channel.setReceiver(this);
- if (channel.getProtocolStack().findProtocol(FORK.class) == null) {
- channel.getProtocolStack().addProtocol(new FORK());
- }
- forkChannel = new ForkChannel(channel, "fork", "fork");
- dispatcher1 = new RpcDispatcher(forkChannel, new Boe1());
- channel.connect("test");
- forkChannel.connect("test");
- }
- public static void main(final String[] args) throws IOException, Exception {
- try (JChannelRunner runner = new JChannelRunner()) {
- Thread.sleep(60 * 1000);
- }
- }
- @Override
- public void close() throws IOException {
- dispatcher1.close();
- forkChannel.close();
- channel.close();
- }
- @Override
- public void viewAccepted(final View new_view) {
- LOGGER.info("viewAccepted:start");
- try {
- final MethodCall call = new MethodCall(Boe1.class.getMethod("boeee"));
- final RequestOptions options = new RequestOptions(ResponseMode.GET_ALL, 0, true, null);
- dispatcher1.callRemoteMethods(null, call, options);
- } catch (final Exception e) {
- e.printStackTrace();
- }
- LOGGER.info("viewAccepted:end");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement