@Override public Object down(Event evt) { return channel != null? channel.down(evt) : null; }
/** Initializes all variables. Used after close() or disconnect(), to be ready for new connect() */ protected JChannel init() { if(local_addr != null) down(new Event(Event.REMOVE_ADDRESS, local_addr)); local_addr=null; cluster_name=null; view=null; return this; }
@Override public Object down(Message msg) { setHeader(msg); return super.down(msg); }
/** * Enables access to event mechanism of a channel and is normally not used by clients directly. * * @param evt sends an Event to a specific protocol layer and receives a response. * @return a response from a particular protocol layer targeted by Event parameter */ public Object down(Event evt) { if(evt.type() == 1) // MSG return ch.down((Message)evt.getArg()); return ch.down(evt); }
public void unlockAll() { ch.down(new Event(Event.UNLOCK_ALL)); }
public void unlockForce(String lock_name) { ch.down(new Event(Event.UNLOCK_FORCE, lock_name)); }
public Object down(Message msg) { if(channel != null) { if(!(channel.isConnected() || channel.isConnecting())) { // return null; throw new IllegalStateException("channel is not connected"); } return channel.down(msg); } return null; }
/** Stops the current flush round. Cluster members are unblocked and allowed to send new and pending messages */ public JChannel stopFlush() { if(!flushSupported()) throw new IllegalStateException("Flush is not supported, add pbcast.FLUSH protocol to your configuration"); down(new Event(Event.RESUME)); return this; }
@Override public long awaitNanos(long nanosTimeout) throws InterruptedException { Long waitLeft = (Long)ch.down(new Event(Event.LOCK_AWAIT, new LockInfo(name, false, true, true, nanosTimeout, TimeUnit.NANOSECONDS))); if(Thread.currentThread().isInterrupted()) throw new InterruptedException(); return waitLeft; }
/** * Stops the current flush of the cluster for the specified flush participants. Flush participants are unblocked and * allowed to send new and pending messages.<p/> * It is an obligation of the application to invoke the matching {@link #startFlush(List, boolean)} method with the * same list of members prior to invocation of this method. * @param flushParticipants the flush participants */ public JChannel stopFlush(List<Address> flushParticipants) { if(!flushSupported()) throw new IllegalStateException("Flush is not supported, add pbcast.FLUSH protocol to your configuration"); down(new Event(Event.RESUME, flushParticipants)); return this; }
@Override public void await() throws InterruptedException { ch.down(new Event(Event.LOCK_AWAIT, new LockInfo(name, false, true, false, 0, TimeUnit.MILLISECONDS))); if(Thread.currentThread().isInterrupted()) throw new InterruptedException(); }
@Override public void signal() { if (holder.get() != Thread.currentThread()) { throw new IllegalMonitorStateException(); } ch.down(new Event(Event.LOCK_SIGNAL, new AwaitInfo(name, false))); }
@Override public void signalAll() { if (holder.get() != Thread.currentThread()) { throw new IllegalMonitorStateException(); } ch.down(new Event(Event.LOCK_SIGNAL, new AwaitInfo(name, true))); } }
/** * {@inheritDoc} * Blocks until the lock has been acquired. Masks interrupts; if an interrupt was received on entry or while * waiting for the lock acquisition, it won't cause the call to return. However, the thread's status will be * set to interrupted when the call returns. */ @Override public void lock() { ch.down(new Event(Event.LOCK, new LockInfo(name, false, false, false, 0, TimeUnit.MILLISECONDS))); holder.set(Thread.currentThread()); }
@Override public Node createNode(Address address) { return this.members.computeIfAbsent(address, key -> { IpAddress ipAddress = (IpAddress) this.dispatcher.getChannel().down(new Event(Event.GET_PHYSICAL_ADDRESS, address)); // Physical address might be null if node is no longer a member of the cluster InetSocketAddress socketAddress = (ipAddress != null) ? new InetSocketAddress(ipAddress.getIpAddress(), ipAddress.getPort()) : new InetSocketAddress(0); // If no logical name exists, create one using physical address String name = Optional.ofNullable(NameCache.get(address)).orElseGet(() -> String.format("%s:%s", socketAddress.getHostString(), socketAddress.getPort())); return new AddressableNode(address, name, socketAddress); }); }
/** * {@inheritDoc} * Releases a lock. Contrary to the parent's implementation, this method can be called more than once: * the release of a lock that has already been released, or is not owned by this thread is a no-op. */ public void unlock() { ch.down(new Event(Event.UNLOCK, new LockInfo(name, false, false, false, 0, TimeUnit.MILLISECONDS))); holder.compareAndSet(Thread.currentThread(), null); // only set if the current thread is actually the holder }
/** * {@inheritDoc} * If the thread is interrupted at entry or during the call, no InterruptedException will be thrown, but the * thread's status will be set to interrupted upon return. An interrupt has therefore no impact on the * return value (success or failure). */ public boolean tryLock() { Boolean retval=(Boolean)ch.down(new Event(Event.LOCK, new LockInfo(name, true, false, false, 0, TimeUnit.MILLISECONDS))); if(retval != null && retval) holder.set(Thread.currentThread()); return retval == null ? false : retval; }
public boolean cancel(boolean mayInterruptIfRunning) { if (sync.innerIsDone()) { return false; } // This will only happen on calling side since it is transient if (channel != null) { return (Boolean)channel.down(new ExecutorEvent( ExecutorEvent.TASK_CANCEL, new Object[] {this, mayInterruptIfRunning})); } return sync.innerCancel(mayInterruptIfRunning); }
@Override public void awaitUninterruptibly() { ch.down(new Event(Event.LOCK_AWAIT, new LockInfo(name, false, false, false, 0, TimeUnit.MILLISECONDS))); }
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; } });