/** * 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); } }
private void reportWriteConnectionStatus(boolean writeConnected) { for (ChannelHandlerWriteSubscription subscription : writeSubscriptions.values()) { subscription.getConnectionWriteFunction().writeValue(writeConnected); } }
/** * Adds a new value to the cache. * * @param newValue the value to be added */ public void add(T newValue) { getWriteFunction().writeValue(newValue); }
/** * Adds a new value to the queue * * @param newValue the new value */ public void add(T newValue) { getWriteFunction().writeValue(newValue); }
/** * 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 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); } } } } });
@Override public void writeValue(Map<String, T> newValue) { for (MapUpdate<T> mapUpdate : mapUpdateCollector.readValue()) { for (String name : mapUpdate.getExpressionsToDelete()) { functions.remove(name); } functions.putAll(mapUpdate.getWriteFunctionsToAdd()); } for (Map.Entry<String, T> entry : newValue.entrySet()) { WriteFunction<T> function = functions.get(entry.getKey()); if (function != null) { function.writeValue(entry.getValue()); } } }
@Override public void writeValue(T newValue) { synchronized(forwardFunction) { valueCache.writeValue(newValue); R forwardValue = forwardFunction.readValue(); forwardWriter.writeValue(forwardValue); } }
@Override public void writeValue(String newValue) { argument.writeValue(format.parseObject(newValue, reference.readValue())); }
@Override public void disconnectRead(ReadRecipe readRecipe) { Map<String, ReadRecipe> splitRecipe = splitRecipe(readRecipe); // Dispatch calls to all the data sources for (Map.Entry<String, ReadRecipe> entry : splitRecipe.entrySet()) { try { dataSources.get(entry.getKey()).disconnectRead(entry.getValue()); } catch(RuntimeException ex) { // If a data source fails, still go and disconnect the others readRecipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }
@Override public void connectRead(ReadRecipe readRecipe) { Map<String, ReadRecipe> splitRecipe = splitRecipe(readRecipe); // Dispatch calls to all the data sources for (Map.Entry<String, ReadRecipe> entry : splitRecipe.entrySet()) { try { retrieveDataSource(entry.getKey()).connectRead(entry.getValue()); } catch (RuntimeException ex) { // If data source fail, still go and connect the others readRecipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }
/** * Simulate a static connection in which the channel name has one exception * and the connection will never change. * <p> * This is a temporary method an will be subject to change in the future. * The aim is to allow to connect expressions that are not channels * but can influence exception and connection state. For example, * to report problems encountered during expression creation as runtime * problems through the normal exception/connection methods. * <p> * In the future, this should be generalized to allow fully fledged expressions * that connect/disconnect and can report errors. * * @param ex the exception to queue * @param connection the connection flag * @param channelName the channel name */ public void connectStatic(Exception ex, boolean connection, String channelName) { writeExceptionCollector.writeValue(ex); writeConnCollector.addChannel(channelName).writeValue(connection); }
@Override public void run() { for (Map.Entry<ChannelHandler, Collection<ChannelReadRecipe>> entry : handlersWithSubscriptions.entrySet()) { ChannelHandler channelHandler = entry.getKey(); Collection<ChannelReadRecipe> channelRecipes = entry.getValue(); for (ChannelReadRecipe channelRecipe : channelRecipes) { try { channelHandler.addReader(channelRecipe.getReadSubscription()); } catch(Exception ex) { // If an error happens while adding the read subscription, // notify the appropriate handler channelRecipe.getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } } } });
/** * Simulate a static connection in which the channel has one exception * and the connection will never change. * <p> * This is a temporary method an will be subject to change in the future. * The aim is to allow to connect expressions that are not channels * but can influence exception and connection state. For example, * to report problems encountered during expression creation as runtime * problems through the normal exception/connection methods. * <p> * In the future, this should be generalized to allow fully fledged expressions * that connect/disconnect and can report errors. * * @param ex the exception to queue * @param connection the connection flag * @param channelName the channel name */ public void connectStaticRead(Exception ex, boolean connection, String channelName) { readExceptionCollector.writeValue(ex); readConnCollector.addChannel(channelName).writeValue(connection); }
@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()); } }
@Override protected synchronized void addWriter(ChannelHandlerWriteSubscription subscription) { writeUsageCounter++; writeSubscriptions.put(subscription.getWriteCache(), subscription); guardedConnect(); if (connectionPayload != null) { subscription.getConnectionWriteFunction().writeValue(isWriteConnected()); } }
try { synchronized(lock) { writeFunction.writeValue(newValue); dataSource.write(currentWriteRecipe, new Runnable() {
channelRecipe.getReadSubscription().getExceptionWriteFunction().writeValue(ex);
/** * Disconnects the given expression. * <p> * This can be used for dynamic expression, to remove and disconnects child * expressions. * * @param expression the expression to disconnect */ public void disconnectReadExpression(DesiredRateExpression<?> expression) { ReadRecipe recipe; synchronized(lock) { recipe = readRecipies.remove(expression); } if (recipe == null) { log.log(Level.SEVERE, "Director was asked to disconnect expression '" + expression + "' which was not found."); } if (!recipe.getChannelReadRecipes().isEmpty()) { try { for (ChannelReadRecipe channelRecipe : recipe.getChannelReadRecipes()) { readConnCollector.removeChannel(channelRecipe.getChannelName()); } dataSource.disconnectRead(recipe); } catch(Exception ex) { recipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }
/** * Connects the given expression. * <p> * This can be used for dynamic expression to add and connect child expressions. * The added expression will be automatically closed when the associated * reader is closed, if it's not disconnected first. * * @param expression the expression to connect */ public void connectReadExpression(DesiredRateExpression<?> expression) { ReadRecipeBuilder builder = new ReadRecipeBuilder(); expression.fillReadRecipe(this, builder); ReadRecipe recipe = builder.build(readExceptionCollector, readConnCollector); synchronized(lock) { readRecipies.put(expression, recipe); } if (!recipe.getChannelReadRecipes().isEmpty()) { try { dataSource.connectRead(recipe); } catch(Exception ex) { recipe.getChannelReadRecipes().iterator().next().getReadSubscription().getExceptionWriteFunction().writeValue(ex); } } }