/** * Send list of event message to the neighbor operations server. * * @param messages a list of messages that will be sent to to the neighbor server * @throws InterruptedException in case of queuing error occurred. */ public void sendMessages(Collection<V> messages) throws InterruptedException { for (V e : messages) { if (!messageQueue.offer(e, 1, TimeUnit.MINUTES)) { LOG.error("NeighborConnection [{}] event messages queue is full " + "more than 1 minute. Operation impossible.", getId()); throw new InterruptedException("Event messages queue is full more than 10 minutes"); } } }
private void sendMessagesToServer(NeighborConnection<MessageTemplate, Message> server, List<Message> messages) { try { LOG.trace("Sending to server {} messages: {}", server.getId(), messages); server.sendMessages(messages); } catch (InterruptedException ex) { LOG.error("Error sending events to server: ", ex); notifyListenersOnServerProblem(server.getId()); } }
private void sendMessagesToServer( NeighborConnection<MessageTemplate, OperationsServiceMsg> server, Collection<OperationsServiceMsg> messages) { try { LOG.trace("Sending to server {} messages: {}", server.getId(), messages); server.sendMessages(messages); } catch (InterruptedException ex) { LOG.error("Error sending events to server: ", ex); } }
/** * Shutdown all neighbors connections and cancel timer task if exist. */ public void shutdown() { for (NeighborConnection<T, V> neigbor : neigbors.values()) { LOG.info("Shuting down neighbor connection {}", neigbor.getId()); neigbor.shutdown(); } neigbors.clear(); }
/** * Stops neighbor Operations server connections. */ public synchronized void shutdown() { if (started) { cancelWorkers(); executor.shutdown(); try { executor.awaitTermination(1, TimeUnit.SECONDS); } catch (InterruptedException ex) { LOG.error("Neighbor Connection {} error terminates ExecutorService", getId(), ex); } thrift.close(); started = false; } else { LOG.debug("Neighbor Connection {} is already stopped or was not started yet", getId()); } }
/** * Get connections from field <code>neigbors</code> and send messages. * * @param msgs <code>Collection</code> of messages */ public void brodcastMessages(Collection<V> msgs) { if (LOG.isTraceEnabled()) { LOG.trace("Broadcasting {} msgs to {} neighbors", msgs.size(), neigbors.values().size()); } for (NeighborConnection<T, V> neighbor : neigbors.values()) { LOG.trace("Broadcasting to {} neighbor", neighbor); try { neighbor.sendMessages(msgs); } catch (InterruptedException ex) { LOG.warn("Failed to send message to {}", neighbor.getId()); } } }
/** * Create connection and send messages. * * @param info is information about connection * @param msgs <code>Collection</code> of messages */ public void sendMessages(ConnectionInfo info, Collection<V> msgs) { NeighborConnection<T, V> neighbor = neigbors.get(getServerId(info)); if (neighbor != null) { try { neighbor.sendMessages(msgs); } catch (InterruptedException ex) { LOG.error("Failed to send message to {}", neighbor.getId()); throw new RuntimeException(ex); } } else { LOG.warn("Can't find server for id {}", getServerId(info)); } }
LOG.debug("Neighbor Connection {} is already started", getId());
@Override public void sendUserRouteInfo( org.kaaproject.kaa.server.operations.service.event.UserRouteInfo routeInfo) { LOG.debug("EventService: sendUserRouteInfo()....."); List<NeighborConnection<MessageTemplate, Message>> servers = neighbors.getNeighbors(); UserRouteInfo userRoute = new UserRouteInfo(routeInfo.getUserId(), routeInfo.getTenantId(), id, transformUpdateType(routeInfo.getRouteOperation())); List<Message> messages = packMessage(userRoute); for (NeighborConnection<MessageTemplate, Message> server : servers) { LOG.debug("Send UserRouteInfo {} to neighbor {}....", userRoute, server.getId()); sendMessagesToServer(server, messages); } }