for (CachePeer cachePeer : listRemoteCachePeers(eventMessages.get(0).getEhcache())) { try { cachePeer.send(eventMessages); } catch (UnmarshalException e) { String message = e.getMessage();
/** * Assembles a list of URLs * * @param localCachePeers * @return an uncompressed payload with catenated rmiUrls. */ public static byte[] assembleUrlList(List localCachePeers) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < localCachePeers.size(); i++) { CachePeer cachePeer = (CachePeer) localCachePeers.get(i); String rmiUrl = null; try { rmiUrl = cachePeer.getUrl(); } catch (RemoteException e) { LOG.error("This should never be thrown as it is called locally"); } if (i != localCachePeers.size() - 1) { sb.append(rmiUrl).append(URL_DELIMITER); } else { sb.append(rmiUrl); } } LOG.debug("Cache peers for this CacheManager to be advertised: {}", sb); return sb.toString().getBytes(); }
/** * Does the actual RMI remote call. * <p> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicatePutNotification(Ehcache cache, Element element) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.put(element); } catch (Throwable t) { LOG.error("Exception on replication of putNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Does the actual RMI remote call. * <p> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicateRemovalNotification(Ehcache cache, Serializable key) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.remove(key); } catch (Throwable t) { LOG.error("Exception on replication of removeNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Fetches a chunk of elements from a remote cache peer * * @param cache the cache to put elements in * @param requestChunk the chunk of keys to request * @param cachePeer the peer to fetch from * @throws java.rmi.RemoteException */ protected void fetchAndPutElements(Ehcache cache, List requestChunk, CachePeer cachePeer) throws RemoteException { List receivedChunk = cachePeer.getElements(requestChunk); for (int i = 0; i < receivedChunk.size(); i++) { Element element = (Element) receivedChunk.get(i); // element could be expired at the peer if (element != null) { cache.put(element, true); } } }
/** * Does the actual RMI remote call. * * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. * */ protected void replicateRemoveAllNotification(Ehcache cache) { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.removeAll(); } catch (Throwable t) { LOG.error("Exception on replication of removeAllNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * @param rmiUrls * @return true if our own hostname and listener port are found in the list. This then means we have * caught our onw multicast, and should be ignored. */ private boolean self(String rmiUrls) { CacheManager cacheManager = peerProvider.getCacheManager(); CacheManagerPeerListener cacheManagerPeerListener = cacheManager.getCachePeerListener("RMI"); if (cacheManagerPeerListener == null) { return false; } List boundCachePeers = cacheManagerPeerListener.getBoundCachePeers(); if (boundCachePeers == null || boundCachePeers.size() == 0) { return false; } CachePeer peer = (CachePeer) boundCachePeers.get(0); try { String cacheManagerUrlBase = peer.getUrlBase(); int baseUrlMatch = rmiUrls.indexOf(cacheManagerUrlBase); return baseUrlMatch != -1; } catch (RemoteException e) { LOG.error("Error geting url base", e); return false; } }
/** * Does the actual RMI remote call. * <p/> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicatePutNotification(Ehcache cache, Element element) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.put(element); } catch (Throwable t) { LOG.error("Exception on replication of putNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Does the actual RMI remote call. * <p> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicateRemovalNotification(Ehcache cache, Serializable key) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.remove(key); } catch (Throwable t) { LOG.error("Exception on replication of removeNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Fetches a chunk of elements from a remote cache peer * * @param cache the cache to put elements in * @param requestChunk the chunk of keys to request * @param cachePeer the peer to fetch from * @throws java.rmi.RemoteException */ protected void fetchAndPutElements(Ehcache cache, List requestChunk, CachePeer cachePeer) throws RemoteException { List receivedChunk = cachePeer.getElements(requestChunk); for (int i = 0; i < receivedChunk.size(); i++) { Element element = (Element) receivedChunk.get(i); // element could be expired at the peer if (element != null) { cache.put(element, true); } } }
/** * Does the actual RMI remote call. * * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. * */ protected void replicateRemoveAllNotification(Ehcache cache) { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.removeAll(); } catch (Throwable t) { LOG.error("Exception on replication of removeAllNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * @param rmiUrls * @return true if our own hostname and listener port are found in the list. This then means we have * caught our onw multicast, and should be ignored. */ private boolean self(String rmiUrls) { CacheManager cacheManager = peerProvider.getCacheManager(); CacheManagerPeerListener cacheManagerPeerListener = cacheManager.getCachePeerListener("RMI"); if (cacheManagerPeerListener == null) { return false; } List boundCachePeers = cacheManagerPeerListener.getBoundCachePeers(); if (boundCachePeers == null || boundCachePeers.size() == 0) { return false; } CachePeer peer = (CachePeer) boundCachePeers.get(0); try { String cacheManagerUrlBase = peer.getUrlBase(); int baseUrlMatch = rmiUrls.indexOf(cacheManagerUrlBase); return baseUrlMatch != -1; } catch (RemoteException e) { LOG.error("Error geting url base", e); return false; } }
/** * Used to send notification to the peer. If Async this method simply add * the element to the replication queue. If not async, searches for the * cachePeer and send the Message. That way the class handles both async and * sync replication Sending is delegated to the peer (of type JGroupsCacheManagerPeerProvider) * * @param cache * @param eventMessage */ protected void sendNotification(Ehcache cache, JGroupEventMessage eventMessage) { final List<CachePeer> peers = this.listRemoteCachePeers(cache); for (final CachePeer peer : peers) { try { peer.send(Arrays.asList(eventMessage)); } catch (RemoteException e) { LOG.warn("Failed to send message '" + eventMessage + "' to peer '" + peer + "'", e); } } }
url = list.get(0).getUrl(); } catch (RemoteException e) { LOG.error("This should never be thrown as it is called locally");
/** * Does the actual RMI remote call. * <p> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicatePutNotification(Ehcache cache, Element element) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.put(element); } catch (Throwable t) { LOG.error("Exception on replication of putNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Does the actual RMI remote call. * <p/> * If a Throwable occurs a SEVERE log message will be logged, but attempts to replicate to the other * peers will continue. */ protected static void replicateRemovalNotification(Ehcache cache, Serializable key) throws RemoteCacheException { List cachePeers = listRemoteCachePeers(cache); for (Object cachePeer1 : cachePeers) { CachePeer cachePeer = (CachePeer) cachePeer1; try { cachePeer.remove(key); } catch (Throwable t) { LOG.error("Exception on replication of removeNotification. " + t.getMessage() + ". Continuing...", t); } } }
/** * Fetches a chunk of elements from a remote cache peer * * @param cache the cache to put elements in * @param requestChunk the chunk of keys to request * @param cachePeer the peer to fetch from * @throws java.rmi.RemoteException */ protected void fetchAndPutElements(Ehcache cache, List requestChunk, CachePeer cachePeer) throws RemoteException { List receivedChunk = cachePeer.getElements(requestChunk); for (int i = 0; i < receivedChunk.size(); i++) { Element element = (Element) receivedChunk.get(i); // element could be expired at the peer if (element != null) { cache.put(element, true); } } }