@Override public String getName() { return this.dispatcher.getChannel().getClusterName(); }
public ChannelCommandDispatcher(MessageDispatcher dispatcher, CommandMarshaller<C> marshaller, Group<Address> group, Duration timeout, CommandDispatcher<C> localDispatcher, Runnable closeTask) { this.dispatcher = dispatcher; this.marshaller = marshaller; this.group = group; this.timeout = timeout; this.localDispatcher = localDispatcher; this.closeTask = closeTask; this.localAddress = dispatcher.getChannel().getAddress(); this.options = new RequestOptions(ResponseMode.GET_ALL, this.timeout.toMillis(), false, FILTER, Message.Flag.DONT_BUNDLE, Message.Flag.OOB); }
@Override public void run() { this.executorService.shutdownNow(); try { this.executorService.awaitTermination(this.timeout.toMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } this.dispatcher.stop(); this.dispatcher.getChannel().setUpHandler(null); // Cleanup any stray listeners for (ExecutorService executor : this.listeners.values()) { PrivilegedAction<List<Runnable>> action = () -> executor.shutdownNow(); WildFlySecurityManager.doUnchecked(action); } this.listeners.clear(); }
@Override public Membership getMembership() { return new ViewMembership(this.dispatcher.getChannel().getAddress(), this.view.get(), this); }
@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); }); }
@Override public Node getLocalMember() { return this.createNode(this.dispatcher.getChannel().getAddress()); }
@Override public void viewAccepted(View view) { View oldView = this.view.getAndSet(view); if (oldView != null) { List<Address> leftMembers = View.leftMembers(oldView, view); if (leftMembers != null) { this.members.keySet().removeAll(leftMembers); } if (this.listeners.isEmpty()) { Address localAddress = this.dispatcher.getChannel().getAddress(); ViewMembership oldMembership = new ViewMembership(localAddress, oldView, this); ViewMembership membership = new ViewMembership(localAddress, view, this); for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) { GroupListener listener = entry.getKey(); ExecutorService executor = entry.getValue(); try { executor.submit(new ListenerTask(listener, oldMembership, membership, view instanceof MergeView)); } catch (RejectedExecutionException e) { // Executor was shutdown } } } } }
@Override protected void finalize() { this.dispatcher.getChannel().close(); }
private Address getLocalAddress() { return this.dispatcher.getChannel().getAddress(); }
@Override public String getName() { return this.dispatcher.getChannel().getClusterName(); }
private Address getCoordinatorAddress() { List<Address> members = this.dispatcher.getChannel().getView().getMembers(); return members.isEmpty() ? null : members.get(0); }
public ChannelCommandDispatcher(MessageDispatcher dispatcher, CommandMarshaller<C> marshaller, Group<Address> group, Duration timeout, CommandDispatcher<C> localDispatcher, Runnable closeTask) { this.dispatcher = dispatcher; this.marshaller = marshaller; this.group = group; this.timeout = timeout; this.localDispatcher = localDispatcher; this.closeTask = closeTask; this.localAddress = dispatcher.getChannel().getAddress(); this.options = new RequestOptions(ResponseMode.GET_ALL, this.timeout.toMillis(), false, FILTER, Message.Flag.DONT_BUNDLE, Message.Flag.OOB); }
@Override public Membership getMembership() { return new ViewMembership(this.dispatcher.getChannel().getAddress(), this.view.get(), this); }
@Override public void run() { this.executorService.shutdownNow(); try { this.executorService.awaitTermination(this.timeout.toMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } this.dispatcher.stop(); this.dispatcher.getChannel().setUpHandler(null); // Cleanup any stray listeners for (ExecutorService executor : this.listeners.values()) { PrivilegedAction<List<Runnable>> action = () -> executor.shutdownNow(); WildFlySecurityManager.doUnchecked(action); } this.listeners.clear(); }
@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); }); }
@Override public Node getLocalMember() { return this.createNode(this.dispatcher.getChannel().getAddress()); }
/** * {@inheritDoc} * @see net.sf.hajdbc.Lifecycle#start() */ @Override public void start() throws SQLException { Channel channel = this.dispatcher.getChannel(); channel.setDiscardOwnMessages(false); // Connect and fetch state try { channel.connect(this.id, null, 0); } catch (Exception e) { throw new SQLException(e); } }
@Override public void viewAccepted(View view) { View oldView = this.view.getAndSet(view); if (oldView != null) { List<Address> leftMembers = View.leftMembers(oldView, view); if (leftMembers != null) { this.members.keySet().removeAll(leftMembers); } if (this.listeners.isEmpty()) { Address localAddress = this.dispatcher.getChannel().getAddress(); ViewMembership oldMembership = new ViewMembership(localAddress, oldView, this); ViewMembership membership = new ViewMembership(localAddress, view, this); for (Map.Entry<GroupListener, ExecutorService> entry : this.listeners.entrySet()) { GroupListener listener = entry.getKey(); ExecutorService executor = entry.getValue(); try { executor.submit(new ListenerTask(listener, oldMembership, membership, view instanceof MergeView)); } catch (RejectedExecutionException e) { // Executor was shutdown } } } } }
/** * {@inheritDoc} * @see net.sf.hajdbc.Lifecycle#stop() */ @Override public void stop() { Channel channel = this.dispatcher.getChannel(); if (channel.isOpen()) { if (channel.isConnected()) { channel.disconnect(); } } }
@Override public void send(final Buffer data, final boolean synchronous, final long timeout) throws Exception { final RequestOptions options = synchronous ? RequestOptions.SYNC() : RequestOptions.ASYNC(); options.exclusionList( dispatcher.getChannel().getAddress() ); options.setTransientFlags( TransientFlag.DONT_LOOPBACK ); options.setTimeout( timeout ); if ( synchronous ) { try { RspList<Object> rspList = dispatcher.castMessage( null, data, options ); handleResponseProblems( rspList, null ); } catch (Exception e) { throw log.unableToSendWorkViaJGroups( e ); } } else { try { dispatcher.castMessageWithFuture( null, data, options ); } catch (RuntimeException e) { throw log.unableToSendWorkViaJGroups( e ); } } }