/** * A template method to actually create the factory * * @param hostName * @param port * @param remoteObjectPort * @param cacheManager * @param socketTimeoutMillis @return a crate CacheManagerPeerListener */ protected CacheManagerPeerListener doCreateCachePeerListener(String hostName, Integer port, Integer remoteObjectPort, CacheManager cacheManager, Integer socketTimeoutMillis) { try { return new RMICacheManagerPeerListener(hostName, port, remoteObjectPort, cacheManager, socketTimeoutMillis); } catch (UnknownHostException e) { throw new CacheException("Unable to create CacheManagerPeerListener. Initial cause was " + e.getMessage(), e); } } }
this.hostName = calculateHostAddress(); assignFreePort(false); } else { this.port = port;
/** * {@inheritDoc} */ public void init() throws CacheException { if (!status.equals(Status.STATUS_UNINITIALISED)) { return; } RMICachePeer rmiCachePeer = null; try { startRegistry(); int counter = 0; populateListOfRemoteCachePeers(); synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { rmiCachePeer = (RMICachePeer) iterator.next(); bind(rmiCachePeer.getUrl(), rmiCachePeer); counter++; } } LOG.debug(counter + " RMICachePeers bound in registry for RMI listener"); status = Status.STATUS_ALIVE; } catch (Exception e) { String url = null; if (rmiCachePeer != null) { url = rmiCachePeer.getUrl(); } throw new CacheException("Problem starting listener for RMICachePeer " + url + ". Initial cause was " + e.getMessage(), e); } }
/** * Stop the listener. It * <ul> * <li>unbinds the objects from the registry * <li>unexports Remote objects * </ul> */ public void dispose() throws CacheException { if (!status.equals(Status.STATUS_ALIVE)) { return; } try { int counter = 0; synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { RMICachePeer rmiCachePeer = (RMICachePeer) iterator.next(); disposeRMICachePeer(rmiCachePeer); counter++; } stopRegistry(); } LOG.debug(counter + " RMICachePeers unbound from registry in RMI listener"); status = Status.STATUS_SHUTDOWN; } catch (Exception e) { throw new CacheException("Problem unbinding remote cache peers. Initial cause was " + e.getMessage(), e); } }
if (isDistributed(cache)) { RMICachePeer rmiCachePeer = null; String url = null; bind(url, rmiCachePeer); } catch (Exception e) { throw new CacheException("Problem starting listener for RMICachePeer "
/** * If a conflict is detected in unique resource use, this method signals the listener to attempt * automatic resolution of the resource conflict. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ public void attemptResolutionOfUniqueResourceConflict() throws IllegalStateException, CacheException { assignFreePort(true); }
/** * Assigns a free port to be the listener port. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ protected void assignFreePort(boolean forced) throws IllegalStateException { if (status != Status.STATUS_UNINITIALISED) { throw new IllegalStateException("Cannot change the port of an already started listener."); } this.port = Integer.valueOf(this.getFreePort()); if (forced) { LOG.warn("Resolving RMI port conflict by automatically using a free TCP/IP port to listen on: " + this.port); } else { LOG.debug("Automatically finding a free TCP/IP port to listen on: " + this.port); } }
/** * Should be called on init because this is one of the last things that should happen on CacheManager startup. */ protected void populateListOfRemoteCachePeers() throws RemoteException { String[] names = cacheManager.getCacheNames(); for (int i = 0; i < names.length; i++) { String name = names[i]; Ehcache cache = cacheManager.getEhcache(name); synchronized (cachePeers) { if (cachePeers.get(name) == null) { if (isDistributed(cache)) { RMICachePeer peer; if (cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { peer = new TransactionalRMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } else { peer = new RMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } cachePeers.put(name, peer); } } } } }
/** * Stop the listener. It * <ul> * <li>unbinds the objects from the registry * <li>unexports Remote objects * </ul> */ public void dispose() throws CacheException { if (!status.equals(Status.STATUS_ALIVE)) { return; } try { int counter = 0; synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { RMICachePeer rmiCachePeer = (RMICachePeer) iterator.next(); disposeRMICachePeer(rmiCachePeer); counter++; } stopRegistry(); } LOG.debug(counter + " RMICachePeers unbound from registry in RMI listener"); status = Status.STATUS_SHUTDOWN; } catch (Exception e) { throw new CacheException("Problem unbinding remote cache peers. Initial cause was " + e.getMessage(), e); } }
if (isDistributed(cache)) { RMICachePeer rmiCachePeer = null; String url = null; bind(url, rmiCachePeer); } catch (Exception e) { throw new CacheException("Problem starting listener for RMICachePeer "
/** * If a conflict is detected in unique resource use, this method signals the listener to attempt * automatic resolution of the resource conflict. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ public void attemptResolutionOfUniqueResourceConflict() throws IllegalStateException, CacheException { assignFreePort(true); }
/** * Assigns a free port to be the listener port. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ protected void assignFreePort(boolean forced) throws IllegalStateException { if (status != Status.STATUS_UNINITIALISED) { throw new IllegalStateException("Cannot change the port of an already started listener."); } this.port = Integer.valueOf(this.getFreePort()); if (forced) { LOG.warn("Resolving RMI port conflict by automatically using a free TCP/IP port to listen on: " + this.port); } else { LOG.debug("Automatically finding a free TCP/IP port to listen on: " + this.port); } }
/** * Should be called on init because this is one of the last things that should happen on CacheManager startup. */ protected void populateListOfRemoteCachePeers() throws RemoteException { String[] names = cacheManager.getCacheNames(); for (int i = 0; i < names.length; i++) { String name = names[i]; Ehcache cache = cacheManager.getEhcache(name); synchronized (cachePeers) { if (cachePeers.get(name) == null) { if (isDistributed(cache)) { RMICachePeer peer; if (cache.getCacheConfiguration().getTransactionalMode().isTransactional()) { peer = new TransactionalRMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } else { peer = new RMICachePeer(cache, hostName, port, remoteObjectPort, socketTimeoutMillis); } cachePeers.put(name, peer); } } } } }
/** * {@inheritDoc} */ public void init() throws CacheException { if (!status.equals(Status.STATUS_UNINITIALISED)) { return; } RMICachePeer rmiCachePeer = null; try { startRegistry(); int counter = 0; populateListOfRemoteCachePeers(); synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { rmiCachePeer = (RMICachePeer) iterator.next(); bind(rmiCachePeer.getUrl(), rmiCachePeer); counter++; } } LOG.debug(counter + " RMICachePeers bound in registry for RMI listener"); status = Status.STATUS_ALIVE; } catch (Exception e) { String url = null; if (rmiCachePeer != null) { url = rmiCachePeer.getUrl(); } throw new CacheException("Problem starting listener for RMICachePeer " + url + ". Initial cause was " + e.getMessage(), e); } }
/** * Stop the listener. It * <ul> * <li>unbinds the objects from the registry * <li>unexports Remote objects * </ul> */ public void dispose() throws CacheException { if (!status.equals(Status.STATUS_ALIVE)) { return; } try { int counter = 0; synchronized (cachePeers) { for (Iterator iterator = cachePeers.values().iterator(); iterator.hasNext();) { RMICachePeer rmiCachePeer = (RMICachePeer) iterator.next(); disposeRMICachePeer(rmiCachePeer); counter++; } stopRegistry(); } LOG.debug(counter + " RMICachePeers unbound from registry in RMI listener"); status = Status.STATUS_SHUTDOWN; } catch (Exception e) { throw new CacheException("Problem unbinding remote cache peers. Initial cause was " + e.getMessage(), e); } }
this.hostName = calculateHostAddress(); assignFreePort(false); } else { this.port = port;
if (isDistributed(cache)) { RMICachePeer rmiCachePeer = null; String url = null; bind(url, rmiCachePeer); } catch (Exception e) { throw new CacheException("Problem starting listener for RMICachePeer "
/** * If a conflict is detected in unique resource use, this method signals the listener to attempt * automatic resolution of the resource conflict. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ public void attemptResolutionOfUniqueResourceConflict() throws IllegalStateException, CacheException { assignFreePort(true); }
/** * Assigns a free port to be the listener port. * * @throws IllegalStateException if the statis of the listener is not {@link net.sf.ehcache.Status#STATUS_UNINITIALISED} */ protected void assignFreePort(boolean forced) throws IllegalStateException { if (status != Status.STATUS_UNINITIALISED) { throw new IllegalStateException("Cannot change the port of an already started listener."); } this.port = Integer.valueOf(this.getFreePort()); if (forced) { LOG.warn("Resolving RMI port conflict by automatically using a free TCP/IP port to listen on: " + this.port); } else { LOG.debug("Automatically finding a free TCP/IP port to listen on: " + this.port); } }
/** * A template method to actually create the factory * * @param hostName * @param port * @param remoteObjectPort * @param cacheManager * @param socketTimeoutMillis @return a crate CacheManagerPeerListener */ protected CacheManagerPeerListener doCreateCachePeerListener(String hostName, Integer port, Integer remoteObjectPort, CacheManager cacheManager, Integer socketTimeoutMillis) { try { return new RMICacheManagerPeerListener(hostName, port, remoteObjectPort, cacheManager, socketTimeoutMillis); } catch (UnknownHostException e) { throw new CacheException("Unable to create CacheManagerPeerListener. Initial cause was " + e.getMessage(), e); } } }