/**
   * Gets called once per {@link #REPLICATION_THREAD_INTERVAL}.
   *
   * <p>Sends accumulated messages in bulk to each peer. i.e. if ther are 100 messages and 1 peer, 1
   * RMI invocation results, not 100. Also, if a peer is unavailable this is discovered in only 1
   * try.
   *
   * <p>Makes a copy of the queue so as not to hold up the enqueue operations.
   *
   * <p>Any exceptions are caught so that the replication thread does not die, and because errors
   * are expected, due to peers becoming unavailable.
   *
   * <p>This method issues warnings for problems that can be fixed with configuration changes.
   */
  private void flushReplicationQueue() {
    List replicationQueueCopy;
    synchronized (replicationQueue) {
      if (replicationQueue.size() == 0) {
        return;
      }

      replicationQueueCopy = new ArrayList(replicationQueue.size());
      for (int i = 0; i < replicationQueue.size(); i++) {
        CacheEventMessage cacheEventMessage = (CacheEventMessage) replicationQueue.get(i);
        replicationQueueCopy.add(cacheEventMessage);
      }
      replicationQueue.clear();
    }

    Ehcache cache = ((CacheEventMessage) replicationQueueCopy.get(0)).cache;
    List cachePeers = listRemoteCachePeers(cache);

    List resolvedEventMessages = extractAndResolveEventMessages(replicationQueueCopy);

    for (int j = 0; j < cachePeers.size(); j++) {
      CachePeer cachePeer = (CachePeer) cachePeers.get(j);
      try {
        cachePeer.send(resolvedEventMessages);
      } catch (UnmarshalException e) {
        String message = e.getMessage();
        if (message.indexOf("Read time out") != 0) {
          LOG.warn(
              "Unable to send message to remote peer due to socket read timeout. Consider increasing"
                  + " the socketTimeoutMillis setting in the cacheManagerPeerListenerFactory. "
                  + "Message was: "
                  + e.getMessage());
        } else {
          LOG.debug("Unable to send message to remote peer.  Message was: " + e.getMessage());
        }
      } catch (Throwable t) {
        LOG.debug("Unable to send message to remote peer.  Message was: " + t.getMessage());
      }
    }
    if (LOG.isWarnEnabled()) {
      int eventMessagesNotResolved = replicationQueueCopy.size() - resolvedEventMessages.size();
      if (eventMessagesNotResolved > 0) {
        LOG.warn(
            eventMessagesNotResolved
                + " messages were discarded on replicate due to reclamation of "
                + "SoftReferences by the VM. Consider increasing the maximum heap size and/or setting the "
                + "starting heap size to a higher value.");
      }
    }
  }
  /**
   * Gets called once per {@link #asynchronousReplicationInterval}.
   *
   * <p>Sends accumulated messages in bulk to each peer. i.e. if ther are 100 messages and 1 peer, 1
   * RMI invocation results, not 100. Also, if a peer is unavailable this is discovered in only 1
   * try.
   *
   * <p>Makes a copy of the queue so as not to hold up the enqueue operations.
   *
   * <p>Any exceptions are caught so that the replication thread does not die, and because errors
   * are expected, due to peers becoming unavailable.
   *
   * <p>This method issues warnings for problems that can be fixed with configuration changes.
   */
  private void flushReplicationQueue() {
    CacheEventMessage head = replicationQueue.peek();
    if (head == null) {
      return;
    }
    Ehcache cache = head.cache;
    List cachePeers = listRemoteCachePeers(cache);

    int limit = replicationQueue.size();
    List<EventMessage> resolvedEventMessages = extractAndResolveEventMessages(limit);

    for (int j = 0; j < cachePeers.size(); j++) {
      CachePeer cachePeer = (CachePeer) cachePeers.get(j);
      try {
        cachePeer.send(resolvedEventMessages);
      } catch (UnmarshalException e) {
        String message = e.getMessage();
        if (message.contains("Read time out") || message.contains("Read timed out")) {
          LOG.warn(
              "Unable to send message to remote peer due to socket read timeout. Consider increasing"
                  + " the socketTimeoutMillis setting in the cacheManagerPeerListenerFactory. "
                  + "Message was: "
                  + message);
        } else {
          LOG.debug("Unable to send message to remote peer.  Message was: " + message);
        }
      } catch (Throwable t) {
        LOG.warn("Unable to send message to remote peer.  Message was: " + t.getMessage(), t);
      }
    }
    if (LOG.isWarnEnabled()) {
      int eventMessagesNotResolved = limit - resolvedEventMessages.size();
      if (eventMessagesNotResolved > 0) {
        LOG.warn(
            eventMessagesNotResolved
                + " messages were discarded on replicate due to reclamation of "
                + "SoftReferences by the VM. Consider increasing the maximum heap size and/or setting the "
                + "starting heap size to a higher value.");
      }
    }
  }
Beispiel #3
0
  @Override
  public void deconnecte(int refRMI, String cause, String phrase) throws RemoteException {
    // enregistrement des infos de la console lors de sa deconnexion,
    // le but etant de garder des informations sur les deconnectes
    VuePersonnage vuePersonnage = personnages.get(refRMI);

    vuePersonnage.getElement().tue(); // au cas ou ce ne serait pas une mort "naturelle"
    vuePersonnage.setTourMort(tour);
    setPhrase(refRMI, "MORT >_< (" + phrase + ")");

    // ajout a la liste des morts
    personnagesMorts.add(vuePersonnage);

    try {
      // fermeture de la console en donnant la raison
      consoleFromRef(refRMI).deconnecte(cause);

    } catch (UnmarshalException e) {
      e.printStackTrace();
    }

    // suppression de la liste des vivants
    ejectePersonnage(refRMI);
  }