public void init() throws Exception { super.init(); if(site == null || site.isEmpty()) throw new IllegalArgumentException("\"site\" must be set"); timer=getTransport().getTimer(); JChannel channel=getProtocolStack().getChannel(); if(channel == null) throw new IllegalStateException("channel must be set"); channel.addAddressGenerator(() -> ExtendedUUID.randomUUID().put(SITE_ID, Util.stringToBytes(site))); }
log.info("Received request to inject view %s", newView); String[] perNode = newView.split(NODE_VIEWS_SEPARATOR); String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString(); log.info("[channel: %s] Injecting a new view: %s", thisNodeAddress, nodeView); long viewId = getProtocolStack().getChannel().getView().getViewId().getId()+1; List<Address> nodes = new ArrayList<>();
@Override protected void _send(Message msg, Address dest) { try { send(msg, dest); } catch (InterruptedIOException iex) { } catch (InterruptedException interruptedEx) { Thread.currentThread().interrupt(); // let someone else handle the interrupt } catch (SocketException e) { if (!this.sock.isClosed() && !stack.getChannel().isClosed()) { log.error("Exception caught while sending message", e); } } catch (IOException e) { if (messenger != null /* && e.getMessage().contains("Operation not permitted") */) { // this is the english Oracle // JDK exception condition we // really want to catch messenger.handleJGroupsIOException(e, dest); } } catch (Throwable e) { log.error("Exception caught while sending message", e); } }
JChannel ch=getProtocolStack().getChannel(); ch.addAddressGenerator(() -> { ExtendedUUID retval=ExtendedUUID.randomUUID();
/** * Returns the fork stack for fork_stack_id (if exitstent), or creates a new fork-stack from protocols and adds it * into the hashmap of fork-stack (key is fork_stack_id). * Method init() will be called on each protocol, from bottom to top. * @param fork_stack_id The key under which the new fork-stack should be added to the fork-stacks hashmap * @param protocols A list of protocols from <em>bottom to top</em> to be inserted. They will be sandwiched * between ForkProtocolStack (top) and ForkProtocol (bottom). The list can be empty (or null) in * which case we won't create any protocols, but still have a separate fork-stack inserted. * @param initialize If false, the ref count 'inits' will not get incremented and init() won't be called. This is * needed when creating a fork stack from an XML config inside of the FORK protocol. The protocols * in the fork stack will only get initialized on the first ForkChannel creation * @return The new {@link ForkProtocolStack}, or the existing stack (if present) */ public synchronized ProtocolStack createForkStack(String fork_stack_id, List<Protocol> protocols, boolean initialize) throws Exception { Protocol bottom; if((bottom=get(fork_stack_id)) != null) { ForkProtocolStack retval=getForkStack(bottom); return initialize? retval.incrInits() : retval; } List<Protocol> prots=new ArrayList<>(); prots.add(bottom=new ForkProtocol(fork_stack_id).setDownProtocol(this)); // add a ForkProtocol as bottom protocol if(protocols != null) prots.addAll(protocols); ForkProtocolStack fork_stack=(ForkProtocolStack)new ForkProtocolStack(getUnknownForkHandler(), prots, fork_stack_id).setChannel(this.stack.getChannel()); fork_stack.init(); if(initialize) fork_stack.incrInits(); fork_stacks.put(fork_stack_id, bottom); return fork_stack; }
@Override protected void doSend(AsciiString cluster_name, byte[] buf, int offset, int length, Address dest) throws Exception { try { super.doSend(cluster_name, buf, offset, length, dest); } catch (SocketException sock_ex) { if (!this.sock.isClosed() && !stack.getChannel().isClosed()) { log.error("Exception caught while sending message", sock_ex); } } catch (IOException e) { if (messenger != null /* && e.getMessage().contains("Operation not permitted") */) { // this is the english Oracle // JDK exception condition we // really want to catch messenger.handleJGroupsIOException(e, dest); } } catch (Throwable e) { log.error("Exception caught while sending message", e); } }
private Object handle(Message message) { Header header = (Header) message.getHeader(this.id); // If this is a request expecting a response, don't leave the requester hanging - send an identifiable response on which it can filter if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) { Message response = message.makeReply().setFlag(message.getFlags()).clearFlag(Message.Flag.RSVP, Message.Flag.INTERNAL); response.putHeader(FORK.ID, message.getHeader(FORK.ID)); response.putHeader(this.id, new Header(Header.RSP, header.req_id, header.corrId)); response.setBuffer(UNKNOWN_FORK_RESPONSE.array()); fork.getProtocolStack().getChannel().down(response); } return null; } });
public StreamingOutputStreamWrapper(Socket outputStreamOwner) throws IOException{ super(); this.outputStreamOwner = outputStreamOwner; this.delegate = new BufferedOutputStream(outputStreamOwner.getOutputStream()); this.channelOwner = stack.getChannel(); }
public StreamingInputStreamWrapper(Socket inputStreamOwner) throws IOException{ super(); this.inputStreamOwner = inputStreamOwner; this.delegate = new BufferedInputStream(inputStreamOwner.getInputStream()); this.channelOwner = stack.getChannel(); }
Channel ch=stack.getChannel(); if(ch != null) { Map m=ch.dumpStats();
public void init() throws Exception { super.init(); if(site == null || site.isEmpty()) throw new IllegalArgumentException("\"site\" must be set"); timer=getTransport().getTimer(); JChannel channel=getProtocolStack().getChannel(); if(channel == null) throw new IllegalStateException("channel must be set"); channel.addAddressGenerator(() -> ExtendedUUID.randomUUID().put(SITE_ID, Util.stringToBytes(site))); }
@Override public void stop() { try { if (_server != null) { if (log.isInfoEnabled()) { log.info(String.format("Stopping server: %s", _serverName)); } boolean stopped = _server.stop(stack.getChannel()); if (log.isInfoEnabled()) { log.info(String.format("%s %s.", _serverName, stopped ? "stopped" : "not stopped (still in use)")); } } } finally { super.stop(); } }
@Override public void stop() { try { if (_server != null) { if (log.isInfoEnabled()) { log.info(String.format("Stopping server: %s", _serverName)); } boolean stopped = _server.stop(stack.getChannel()); if (log.isInfoEnabled()) { log.info(String.format("%s %s.", _serverName, stopped ? "stopped" : "not stopped (still in use)")); } } } finally { super.stop(); } }
log.info("Received request to inject view %s", newView); String[] perNode = newView.split(NODE_VIEWS_SEPARATOR); String thisNodeAddress = getProtocolStack().getChannel().getAddressAsString(); log.info("[channel: %s] Injecting a new view: %s", thisNodeAddress, nodeView); long viewId = getProtocolStack().getChannel().getView().getViewId().getId()+1; List<Address> nodes = new ArrayList<>();
@Override public void start() throws Exception { if (isClusteringEnabled()) { int serverPort = getServerPort(); if (_serverFactory != null) { _server = _serverFactory.getServer(serverPort); } else { _server = Servers.getServer(serverPort); } _serverName = _server.getClass().getSimpleName(); if (log.isInfoEnabled()) { log.info(String.format("Starting %s on port %s for channel address: %s", _serverName, serverPort, stack .getChannel().getAddress())); } boolean started = _server.start(stack.getChannel()); if (log.isInfoEnabled()) { log.info(String.format("%s %s.", _serverName, started ? "started" : "reused (pre-existing)")); } } super.start(); }
@Override public void start() throws Exception { if (isClusteringEnabled()) { int serverPort = getServerPort(); if (_serverFactory != null) { _server = _serverFactory.getServer(serverPort); } else { _server = Servers.getServer(serverPort); } _serverName = _server.getClass().getSimpleName(); if (log.isInfoEnabled()) { log.info(String.format("Starting %s on port %s for channel address: %s", _serverName, serverPort, stack .getChannel().getAddress())); } boolean started = _server.start(stack.getChannel()); if (log.isInfoEnabled()) { log.info(String.format("%s %s.", _serverName, started ? "started" : "reused (pre-existing)")); } } super.start(); }
@Override protected void _send(Message msg, Address dest) { try { send(msg, dest); } catch(InterruptedIOException iex) { } catch(InterruptedException interruptedEx) { Thread.currentThread().interrupt(); // let someone else handle the interrupt } catch(SocketException e) { if (!this.sock.isClosed() && !stack.getChannel().isClosed()) { log.error("Exception caught while sending message", e); } // log.trace(Util.getMessage("SendFailure"), // local_addr, (dest == null? "cluster" : dest), msg.size(), e.toString(), msg.printHeaders()); } catch (IOException e) { if (messenger != null /*&& e.getMessage().contains("Operation not permitted")*/) { // this is the english Oracle JDK exception condition we really want to catch messenger.handleJGroupsIOException(e, dest); } } catch(Throwable e) { log.error("Exception caught while sending message", e); // Util.getMessage("SendFailure"), // local_addr, (dest == null? "cluster" : dest), msg.size(), e.toString(), msg.printHeaders()); } }
JChannel ch=getProtocolStack().getChannel(); ch.addAddressGenerator(() -> { ExtendedUUID retval=ExtendedUUID.randomUUID();
/** * Returns the fork stack for fork_stack_id (if exitstent), or creates a new fork-stack from protocols and adds it * into the hashmap of fork-stack (key is fork_stack_id). * Method init() will be called on each protocol, from bottom to top. * @param fork_stack_id The key under which the new fork-stack should be added to the fork-stacks hashmap * @param protocols A list of protocols from <em>bottom to top</em> to be inserted. They will be sandwiched * between ForkProtocolStack (top) and ForkProtocol (bottom). The list can be empty (or null) in * which case we won't create any protocols, but still have a separate fork-stack inserted. * @param initialize If false, the ref count 'inits' will not get incremented and init() won't be called. This is * needed when creating a fork stack from an XML config inside of the FORK protocol. The protocols * in the fork stack will only get initialized on the first ForkChannel creation * @return The new {@link ForkProtocolStack}, or the existing stack (if present) */ public synchronized ProtocolStack createForkStack(String fork_stack_id, List<Protocol> protocols, boolean initialize) throws Exception { Protocol bottom; if((bottom=get(fork_stack_id)) != null) { ForkProtocolStack retval=getForkStack(bottom); return initialize? retval.incrInits() : retval; } List<Protocol> prots=new ArrayList<>(); prots.add(bottom=new ForkProtocol(fork_stack_id).setDownProtocol(this)); // add a ForkProtocol as bottom protocol if(protocols != null) prots.addAll(protocols); ForkProtocolStack fork_stack=(ForkProtocolStack)new ForkProtocolStack(getUnknownForkHandler(), prots, fork_stack_id).setChannel(this.stack.getChannel()); fork_stack.init(); if(initialize) fork_stack.incrInits(); fork_stacks.put(fork_stack_id, bottom); return fork_stack; }
private Object handle(Message message) { Header header = (Header) message.getHeader(this.id); // If this is a request expecting a response, don't leave the requester hanging - send an identifiable response on which it can filter if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) { Message response = message.makeReply().setFlag(message.getFlags()).clearFlag(Message.Flag.RSVP, Message.Flag.INTERNAL); response.putHeader(FORK.ID, message.getHeader(FORK.ID)); response.putHeader(this.id, new Header(Header.RSP, header.req_id, header.corrId)); response.setBuffer(UNKNOWN_FORK_RESPONSE.array()); fork.getProtocolStack().getChannel().down(response); } return null; } });