@Override public String toString(){ return getProviderURL(); }
public void addCMIReference(final CMIReference cmiReference) { Set<CMIReference> cmiReferences = refs.get(cmiReference.getServerRef().getProtocol()); if(cmiReferences == null) { cmiReferences = new HashSet<CMIReference>(); refs.put(cmiReference.getServerRef().getProtocol(), cmiReferences); } cmiReferences.add(cmiReference); }
/** * @param message * @param providerUrl */ public ServerNotFoundException(final String message, final String providerUrl) { super(message); try { serverRef = new ServerRef(providerUrl); } catch (MalformedURLException e) { serverRef = null; } catch (UnknownHostException e) { serverRef = null; } }
private String getServerConfigPath(final ServerRef serverRef) { return getServerConfigPath() + "/" + serverRef.getInetAddress().getHostAddress() + "_" + serverRef.getPort(); }
throws ProtocolNotFoundException, ObjectNotFoundException, ClassCastException, NamingException { ServerRef serverRef = cmiReference.getServerRef(); String protocol = serverRef.getProtocol(); env.put(Context.PROVIDER_URL, serverRef.getProviderURL()); Context chosenContext = new InitialContext(env); logger.debug("Lookup {0} on {1}", bindName, serverRef.getProviderURL()); Object object; try {
/** * @param cmiReference * a reference on a instance * @return a path in the distributed tree for a instance */ private String getCMIReferencePath(final CMIReference cmiReference) { return getProtocolPath(getObjectPath(cmiReference.getObjectName()), cmiReference.getServerRef().getProtocol()) + "/" + cmiReference.getServerRef().getInetAddress().getHostAddress() + "_" + cmiReference.getServerRef().getPort(); }
@Override public boolean equals(final Object obj) { return super.equals(obj); }
/** * Returns a list of CMIReference that references the local servers. * @param cmiRefs a list of CMIReference * @return a list of CMIReference that references the local servers */ public List<T> choose(final Collection<T> cmiRefs) { List<T> localServers = new ArrayList<T>(); for(T cmiRef : cmiRefs) { // Gets the reference of server that have deployed the object ServerRef serverRef = cmiRef.getServerRef(); // Gets its address InetAddress inetAddress = serverRef.getInetAddress(); try { // Checks if the addresses match if(isLocal(inetAddress)) { // Local address: adds reference in the first position localServers.add(cmiRef); } } catch (SocketException e) { LOGGER.error("Cannot know if is local or not", e); throw new RuntimeException("Cannot know if is local or not", e); } } return localServers; }
@SuppressWarnings("unchecked") public CMIReferenceable<EJBObject> create(final CMIReference cmiReference) throws PoolException { ServerRef serverRef = cmiReference.getServerRef(); String protocol = serverRef.getProtocol(); throw new PoolException("Cannot get a class name for the initial context factory", e); env.put(Context.PROVIDER_URL, serverRef.getProviderURL()); Context chosenContext; try{ LOGGER.debug("Lookup {0} on {1}", bindName, serverRef.getProviderURL()); ejbHome = (EJBHome) PortableRemoteObject.narrow(chosenContext.lookup(bindName), homeClass); } catch (NamingException e) { LOGGER.info("No ClientClusterViewProvider is bound with the name {0} at the url {1}", bindName, serverRef.getProviderURL(), e); throw new NamingPoolException( "No ClientClusterViewProvider is bound with the name "+bindName +" at the url "+serverRef.getProviderURL(), e); } finally { try {
@Override public boolean equals(final Object obj) { if(obj == null || !(obj instanceof CMIReference)) { return false; } CMIReference cmiReference = (CMIReference) obj; return objectName.equals(cmiReference.objectName) && serverRef.equals(cmiReference.serverRef); }
@Override public String toString() { return serverRef.getProviderURL() + "/" + objectName; }
public boolean removeCMIReference(final CMIReference cmiReference) { Set<CMIReference> cmiReferences = refs.get(cmiReference.getServerRef().getProtocol()); if(cmiReferences == null) { return false; } return cmiReferences.remove(cmiReference); }
/** * Sets the load-factor for the server with the given address. * @param serverRef a reference on a server * @param loadFactor the load-factor for the server with the given address * @throws UnsupportedOperationException if the used manager is at client-side * @throws MalformedURLException if the URL is malformed * @throws UnknownHostException if the given host cannot be resolved */ public void setLoadFactor(final String serverRef, final String loadFactor) throws UnsupportedOperationException, MalformedURLException, UnknownHostException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } ((ServerClusterViewManager) clusterViewManager).setLoadFactor(new ServerRef(serverRef), new Integer(loadFactor)); }
/** * @param serverRef * a reference on CMI server * @return references on clustered object for a given server */ public final Set<CMIReference> getCMIRefsForServerRef( final ServerRef serverRef) { Set<CMIReference> cmiRefs = new HashSet<CMIReference>(); for (String objectName : getObjectNames()) { try { for (CMIReference cmiRef : getCMIReferences(objectName)) { ServerRef serverId = cmiRef.getServerRef(); if (serverId.equals(serverRef)) { cmiRefs.add(cmiRef); } } } catch (ObjectNotFoundException e) { // Not an error! } } return cmiRefs; }
public void removeServerRef(final String serverRef) { for(Set<CMIReference> cmiReferences : refs.values()) { Iterator<CMIReference> it = cmiReferences.iterator(); while(it.hasNext()) { if(it.next().getServerRef().getProviderURL().equals(serverRef)) { it.remove(); } } } }
/** * Adds a CMIReference to the cluster view. * * @param cmiReference * a reference on an instance */ public void addCMIReference(final CMIReference cmiReference) { ServerRef serverRef = cmiReference.getServerRef(); if (!(serverRef instanceof ServerId)) { LOGGER.error("Not a valid CMIReference: {0} is not a server id.", serverRef); throw new IllegalArgumentException("Not a valid CMIReference: " + serverRef + " is not a server id."); } String path = getCMIReferencePath(cmiReference); distributedTree.add(path, cmiReference); registerPath( serverRef.getProtocol() + "_" + cmiReference.getObjectName(), path); LOGGER.debug("Added {0}...[srvref:{1}, objpath:{2} ]", cmiReference, serverRef, path); }
/** * Adds a server to the blacklist. * @param serverName a reference on a server * @throws UnsupportedOperationException if the used manager is at client-side * @throws MalformedURLException if the URL is malformed * @throws UnknownHostException if the given host cannot be resolved */ public void addServerToBlackList(final String serverName) throws UnsupportedOperationException, MalformedURLException, UnknownHostException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } ((ServerClusterViewManager) clusterViewManager).addServerToBlackList(new ServerRef(serverName)); }
/** * @param protocolName a name of protocol * @return the reference on the local registry for the given protocol * @throws IllegalArgumentException if the given protocol name doesn't exist * @throws UnsupportedOperationException if the used manager is at client-side */ public String getRefOnLocalRegistry(final String protocolName) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } ServerRef serverRef; try { serverRef = ((ServerClusterViewManager) clusterViewManager).getRefOnLocalRegistry(protocolName); } catch (ProtocolNotFoundException e) { LOGGER.error("Unknown protocol " + protocolName, e); throw new IllegalArgumentException("Unknown protocol " + protocolName, e); } return serverRef.getProviderURL(); }
String objectPath = getObjectPath(objectName); String refPath = getCMIReferencePath(cmiReference); String protocolPath = getProtocolPath(objectPath, serverRef.getProtocol()); LOGGER.debug("Removing {0}...[srvref:{1}, objpath:{2}, refpath:{3}, protopath:{4}]", cmiReference, serverRef, objectPath, refPath, protocolPath); distributedTree.remove(refPath); unRegisterPath(serverRef.getProtocol() + "_" + objectName);
/** * Removes a server from the blacklist. * @param serverName a reference on a server * @throws UnsupportedOperationException if the used manager is at client-side * @throws MalformedURLException if the URL is malformed * @throws UnknownHostException if the given host cannot be resolved */ public void removeServerFromBlackList(final String serverName) throws UnsupportedOperationException, MalformedURLException, UnknownHostException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } ((ServerClusterViewManager) clusterViewManager).removeServerFromBlackList(new ServerRef(serverName)); }