/** * Notifies all writers of an error condition. * * @param ex the exception to notify */ protected synchronized final void reportExceptionToAllWriters(Exception ex) { for (ChannelHandlerWriteSubscription subscription : writeSubscriptions.values()) { subscription.getExceptionWriteFunction().writeValue(ex); } }
@Override public boolean equals(Object obj) { if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final ChannelWriteRecipe other = (ChannelWriteRecipe) obj; if ((this.channelName == null) ? (other.channelName != null) : !this.channelName.equals(other.channelName)) { return false; } if (this.writeSubscription != other.writeSubscription && (this.writeSubscription == null || !this.writeSubscription.equals(other.writeSubscription))) { return false; } return true; }
@Override protected synchronized void addWriter(ChannelHandlerWriteSubscription subscription) { writeUsageCounter++; writeSubscriptions.put(subscription.getWriteCache(), subscription); guardedConnect(); if (connectionPayload != null) { subscription.getConnectionWriteFunction().writeValue(isWriteConnected()); } }
@Override protected synchronized void removeWrite(ChannelHandlerWriteSubscription subscription) { writeUsageCounter--; writeSubscriptions.remove(subscription.getWriteCache()); guardedDisconnect(); }
@Override public int hashCode() { int hash = 5; hash = 71 * hash + (this.channelName != null ? this.channelName.hashCode() : 0); hash = 71 * hash + (this.writeSubscription != null ? this.writeSubscription.hashCode() : 0); return hash; }
private void reportWriteConnectionStatus(boolean writeConnected) { for (ChannelHandlerWriteSubscription subscription : writeSubscriptions.values()) { subscription.getConnectionWriteFunction().writeValue(writeConnected); } }
/** * Builds the recipe. * <p> * To finish building the recipe, one needs to specify where to send errors * and where to send the connection status changes. * * @param exceptionWriteFunction where exception should be routed * @param connectionCollector where connection status should be routed * @return a new WriteRecipe */ public WriteRecipe build(WriteFunction<Exception> exceptionWriteFunction, ConnectionCollector connectionCollector) { Set<ChannelWriteRecipe> recipes = new HashSet<>(); for (Map.Entry<String, Collection<WriteCache<?>>> entry : caches.entrySet()) { String channelName = entry.getKey(); Collection<WriteCache<?>> valueCaches = entry.getValue(); for (WriteCache<?> valueCache : valueCaches) { recipes.add(new ChannelWriteRecipe(channelName, new ChannelHandlerWriteSubscription(valueCache, exceptionWriteFunction, connectionCollector.addChannel(channelName)))); } } return new WriteRecipe(recipes); }
for (ChannelWriteRecipe channelWriteRecipe : writeRecipe.getChannelWriteRecipes()) { ChannelHandler channel = channel(channelWriteRecipe.getChannelName()); planner.addChannel(channel, channelWriteRecipe.getWriteSubscription().getWriteCache().getValue(), channelWriteRecipe.getWriteSubscription().getWriteCache().getPrecedingChannels());
@Override public void run() { for (Map.Entry<ChannelHandler, Collection<ChannelHandlerWriteSubscription>> entry : handlers.entrySet()) { ChannelHandler channelHandler = entry.getKey(); Collection<ChannelHandlerWriteSubscription> subscriptions = entry.getValue(); for (ChannelHandlerWriteSubscription subscription : subscriptions) { try { channelHandler.addWriter(subscription); } catch (Exception ex) { // If an error happens while adding the write subscription, // notify the appropriate handler subscription.getExceptionWriteFunction().writeValue(ex); } } } } });
/** * Notifies all readers and writers of an error condition. * * @param ex the exception to notify */ protected synchronized final void reportExceptionToAllReadersAndWriters(Exception ex) { for (MonitorHandler monitor : monitors.values()) { monitor.subscription.getExceptionWriteFunction().writeValue(ex); } for (ChannelHandlerWriteSubscription subscription : writeSubscriptions.values()) { subscription.getExceptionWriteFunction().writeValue(ex); } }
@Override protected synchronized void addWriter(ChannelHandlerWriteSubscription subscription) { super.addWriter(subscription); // If already connected and read only, we need to notify this writer if (sentReadOnlyException) { subscription.getExceptionWriteFunction().writeValue(createReadOnlyException()); } }
channelWriteRecipe.getWriteSubscription().getExceptionWriteFunction().writeValue(ex);