@Override public String toString(){ return getProviderURL(); }
@Override public String toString() { return serverRef.getProviderURL() + "/" + objectName; }
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(); } } } }
/** * Gets all objects hosted on a given server started with the given * protocol. * * @param serverUrl * a server reference * @param protocolName * a given protocol * @return the set of references on objects for the given server. */ public final Set<String> getServerObjectForProtocol(final String serverUrl, final String protocolName) { Set<String> objectRefs = new HashSet<String>(); for (String objectName : getObjectNames()) { try { for (CMIReference cmiRef : getCMIReferences(objectName, protocolName)) { if (cmiRef.getServerRef().getProviderURL() .equals(serverUrl)) { objectRefs.add(objectName); } } } catch (ObjectNotFoundException e) { // Not an error! } } return objectRefs; }
/** * @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(); }
/** * Returns a list of String representing a ServerRef for an object with the given name and protocol. * @param objectName a name of object * @param protocolName a name of protocol * @return a list of String representing a ServerRef for an object with the given name and protocol * @throws IllegalArgumentException if none object has the given name */ public List<String> getServerRefs(final String objectName, final String protocolName) throws IllegalArgumentException { Collection<CMIReference> cmiReferences; try { cmiReferences = clusterViewManager.getCMIReferences(objectName, protocolName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } List<String> stringOfCMIRefs = new ArrayList<String>(cmiReferences.size()); for(CMIReference cmiReference : cmiReferences) { stringOfCMIRefs.add(cmiReference.getServerRef().getProviderURL()); } return stringOfCMIRefs; }
/** * Returns a list of String representing a ServerRef for an object with the given name. * @param objectName a name of object * @return a list of String representing a ServerRef for an object with the given name * @throws IllegalArgumentException if none object has the given name * @throws UnsupportedOperationException if the used manager is at client-side */ public List<String> getServerRefs(final String objectName) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } Collection<CMIReference> cmiReferences; try { cmiReferences = ((ServerClusterViewManager) clusterViewManager).getCMIReferences(objectName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } List<String> stringOfCMIRefs = new ArrayList<String>(cmiReferences.size()); for(CMIReference cmiReference : cmiReferences) { stringOfCMIRefs.add(cmiReference.getServerRef().getProviderURL()); } return stringOfCMIRefs; }
env.put(Context.PROVIDER_URL, serverRef.getProviderURL()); Context chosenContext = new InitialContext(env); logger.debug("Lookup {0} on {1}", bindName, serverRef.getProviderURL()); Object object; try {
/** * Always choose the same server (called singleton) on any client. * @param cmiReferences a list of references * @throws NoLoadBalanceableException if no server available * @return the singleton */ @Override public synchronized T choose(final Collection<T> cmiReferences) throws NoLoadBalanceableException { if (cmiReferences == null || cmiReferences.isEmpty()) { LOGGER.error("The given list is null or empty: " + cmiReferences); throw new NoLoadBalanceableException("The given list is null or empty: " + cmiReferences); } // Search for an available singleton for(String serverRef : serverRefs) { for(T cmiReference : cmiReferences) { if(serverRef.equals(cmiReference.getServerRef().getProviderURL())) { LOGGER.debug("Found a singleton: {0}", serverRef); return cmiReference; } } } // None singleton is available, use an other policy. return policy.choose(cmiReferences); }
/** * Returns the list of Provider URL. * * @param protocolName * a name of protocol * @return providers of the cluster view for the protocol with the given * name * @throws ServerClusterViewManagerException * if none provider exists for the protocol with the given name */ public final List<String> getProviderURLs(final String protocolName) throws ServerClusterViewManagerException { String providerName = getConfig().getClientProviderName(); ArrayList<String> providerURLs = new ArrayList<String>(); try { for (CMIReference cmiReference : getCMIReferences(providerName, protocolName)) { providerURLs.add(cmiReference.getServerRef().getProviderURL()); } } catch (ObjectNotFoundException e) { LOGGER.error( "Cannot get CMIReferences for the provider whith name {0}", providerName, e); throw new ServerClusterViewManagerException( "Cannot get CMIReferences for the provider whith name " + providerName, e); } return providerURLs; }
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 {
private Object findStubOrProxy(final String objectName) throws CMIContextException, ObjectNotFoundException, NamingException { // Choose a server to perform the request. Collection<CMIReference> cmiReferences = clusterViewManager.getCMIReferences(objectName, protocol); IPolicy<CMIReference> policy = clusterViewManager.getPolicy(objectName); CMIReference cmiReference; try { cmiReference = policy.choose(cmiReferences); } catch (NoLoadBalanceableException e) { LOGGER.error("Cannot choose a CMIReference in the list {0} with LB policy {1}", cmiReferences, policy, e); throw new CMIContextException( "Cannot choose a CMIReference in the list " + cmiReferences + " with LB policy " + policy, e); } ServerRef serverRef = cmiReference.getServerRef(); String pURL = serverRef.getProviderURL(); LOGGER.debug("Chosen providerURL: {0}", pURL); Context context; context = getRealContext(pURL, initialContextFactoryName); try { return context.lookup(objectName); } finally { try { context.close(); } catch (NamingException e) { LOGGER.debug("Unable to close the context", e); } } }
lastServerRef = nextServerRef; String pURL = nextServerRef.getProviderURL(); Context context = getRealContext(pURL, initialContextFactoryName); try { String pURL = serverRef.getProviderURL(); LOGGER.debug("Chosen providerURL: {0}", pURL); Context context = getRealContext(pURL, initialContextFactoryName);
lastServerRef = nextServerRef; String pURL = nextServerRef.getProviderURL(); Context context = getRealContext(pURL, initialContextFactoryName); try { String pURL = serverRef.getProviderURL(); LOGGER.debug("Chosen providerURL: {0}", pURL); Context context = getRealContext(pURL, initialContextFactoryName);
lastServerRef = nextServerRef; String pURL = nextServerRef.getProviderURL(); Context context = getRealContext(pURL, initialContextFactoryName); try { String pURL = serverRef.getProviderURL(); LOGGER.debug("Chosen providerURL: {0}", pURL); Context context = getRealContext(pURL, initialContextFactoryName);
lastServerRef = nextServerRef; String pURL = nextServerRef.getProviderURL(); Context context = getRealContext(pURL, initialContextFactoryName); try { String pURL = serverRef.getProviderURL(); LOGGER.debug("Chosen providerURL: {0}", pURL); Context context = getRealContext(pURL, initialContextFactoryName);