/** * 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; }
Class<?> itfClass = clusterViewManager.getInterface(objectName); InvocationHandler invocationHandler; if(!clusterViewManager.hasState(objectName) && !clusterViewManager.isReplicated(objectName)) { if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its stubs for EJBObject", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new EJBObjectFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); clusterViewManager.setPool(objectName, pool); if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its mandatories", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new StubOrProxyFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); clusterViewManager.setPool(objectName, pool); if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its stubs for EJBHome", objectName);
IPolicy<CMIReference> policy; try { policy = clusterViewManager.getPolicy(objectName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e);
@Override protected void checkInitialized() throws HAEJBInvocationHandlerException { try { synchronized(clusterViewManager){ // The first time, create a pool to share stubs for EJBHome if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its stubs for EJBHome", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new StubOrProxyFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); } clusterViewManager.setPool(objectName, pool); } } if(classLoader == null) { classLoader = Thread.currentThread().getContextClassLoader(); } if(remoteClass == null) { remoteClass = clusterViewManager.getRemoteClass(objectName); } } catch (Exception e) { LOGGER.error("Cannot init the HA EJBHome proxy", e); throw new HAEJBInvocationHandlerException("Cannot init the HA EJBHome proxy", e); } }
/** * Returns a policy to access to the object with the given name. * @param objectName a name of object * @return a policy to access to the object with the given name * @throws PolicyFactoryException if the policy cannot be constructed * @throws ObjectNotFoundException if none object has the given name */ @SuppressWarnings("unchecked") public IPolicy<T> getPolicy(final String objectName) throws PolicyFactoryException, ObjectNotFoundException { Class<? extends IPolicy<T>> policyClass; try { policyClass = (Class<? extends IPolicy<T>>) clusterViewManager.getPolicyClass(objectName); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the policy class", e); throw new PolicyFactoryException("Error while finding the policy class", e); } Map<String, Object> properties = clusterViewManager.getPropertiesForPolicy(objectName); Class<? extends IStrategy<T>> strategyClass; try { strategyClass = (Class<? extends IStrategy<T>>) clusterViewManager.getStrategyClass(objectName); } catch (ClusterViewManagerException e) { LOGGER.error("Error while finding the strategy class", e); throw new PolicyFactoryException("Error while finding the strategy class", e); } return getPolicy(policyClass, strategyClass, properties); }
synchronized(clusterViewManager){ if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its stubs for EJBObject", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new EJBObjectFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); clusterViewManager.setPool(objectName, pool); homeClass = (Class<? extends EJBHome>) clusterViewManager.getInterface(objectName);
|| !clusterViewManager.getState().equals(ClusterViewManager.State.AVAILABLE); if(clusterViewManager.isClustered(name)) { LOGGER.debug("{0} is clustered", name); try { lbPolicy = clusterViewManager.getPolicy(dummyRegistryName); } catch (ObjectNotFoundException e) { LOGGER.error("Cannot get LB policy for object {0}", dummyRegistryName, e); loadBalanceables = clusterViewManager.getCMIReferences(dummyRegistryName, protocol); } catch (ObjectNotFoundException e) { LOGGER.error("Cannot get node list for {0}", dummyRegistryName, e);
@Override protected void checkInitialized() throws POJOInvocationHandlerException { try { synchronized(clusterViewManager){ // The first time, create a pool to share stubs for EJBHome if(clusterViewManager.getPool(objectName) == null) { LOGGER.debug("First lookup on {0}: creation of the pool for its stubs for EJBHome", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new StubOrProxyFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); } clusterViewManager.setPool(objectName, pool); } } } catch (Exception e) { LOGGER.error("Cannot init the pool", e); throw new POJOInvocationHandlerException("Cannot init the pool", e); } if(classLoader == null) { try { classLoader = Thread.currentThread().getContextClassLoader(); } catch(Exception e) { throw new POJOInvocationHandlerException( "Cannot retrieve the classloader for object with name " + objectName, e); } } }
|| !clusterViewManager.getState().equals(ClusterViewManager.State.AVAILABLE); lbPolicy = clusterViewManager.getPolicy(dummyRegistryName); } catch (ObjectNotFoundException e) { LOGGER.error("Cannot get LB policy for object {0}", dummyRegistryName, e); loadBalanceables = clusterViewManager.getCMIReferences(dummyRegistryName, protocol); } catch (ObjectNotFoundException e) { LOGGER.error("Cannot get node list for {0}", dummyRegistryName, e);
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); } } }
/** * Returns the max waiters of pool of CMIReferenceable for a object with the given name. * @param objectName a name of object * @return the maximal waiters of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if none object has the given name */ public Integer getMaxPoolWaiters(final String objectName) throws IllegalArgumentException { try { return clusterViewManager.getPoolConfiguration(objectName).getMaxWaiters(); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
env.put(Context.INITIAL_CONTEXT_FACTORY, clusterViewManager.getInitialContextFactoryName(protocol)); env.put(Context.PROVIDER_URL, serverRef.getProviderURL()); Context chosenContext = new InitialContext(env); Class<?> interfaceClass = clusterViewManager.getInterface(bindName);
clusterViewManager.addObjectToWatch(objectName); try { itf = (Class<T>) clusterViewManager.getInterface(objectName); } catch (ObjectNotFoundException e) { logger.error("Cannot retrieve the interface for object with name " + objectName, e);
@SuppressWarnings("unchecked") @Override protected CMIReferenceable<T> getCMIReferenceable(final CMIReference cmiReference) throws Exception { return (CMIReferenceable<T>) clusterViewManager.getPool(objectName).get(cmiReference); }
Class<? extends IPolicy> policyClass; try { policyClass = clusterViewManager.getPolicyClass(objectName); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e);
private Object findClusteredObject(final String name) throws CMIContextException { try { clusterViewManager.addObjectToWatch(name); if(!clusterViewManager.isProxyEnabled(name)) { try { return findStubOrProxy(name); } catch (NamingException e) { LOGGER.error("Cannot get a proxy (or stub) for {0}.", name, e); throw new CMIContextException("Cannot get a proxy (or stub) for " + name, e); } } // Builds a CMI proxy CMIProxy cmiProxy; try { cmiProxy = CMIProxyFactory.newCMIProxy(clusterViewManager, name, protocol); } catch (Exception e) { LOGGER.error("Cannot get a CMI proxy for {0}.", name, e); throw new CMIContextException("Cannot get a CMI proxy for " + name, e); } // Returns the CMI proxy return cmiProxy; } catch (Exception e) { LOGGER.error("Cannot find the clustered object object {0}", name, e); throw new CMIContextException( "Cannot find the clustered object object " + name, e); } }
/** * Compares the load-factors of two {@link LoadBalanceable} with the load factor of their {@link ServerRef}. * @param loadBalanceable1 the first {@link LoadBalanceable} * @param loadBalanceable2 the second {@link LoadBalanceable} * @return a negative integer, zero, or a positive integer as the first server has a smaller, * equal to, or greater load-factor than than the second */ public int compare(final T loadBalanceable1, final T loadBalanceable2) { ServerRef serverRef1 = loadBalanceable1.getServerRef(); ServerRef serverRef2 = loadBalanceable2.getServerRef(); try { int factor1 = clusterViewManager.getLoadFactor(serverRef1); int factor2 = clusterViewManager.getLoadFactor(serverRef2); return Integer.valueOf(factor1).compareTo(factor2); } catch (ServerNotFoundException e) { LOGGER.error("Cannot compare the load factors of servers {0} and {1}.", serverRef1, serverRef2, e); return 0; } }
this.protocol = protocol; this.replicationEnabled = clusterViewManager instanceof ServerClusterViewManager; this.dummyRegistryName = clusterViewManager.getConfig().getDummyRegistryName(); this.dummyRegistryEnabled = clusterViewManager.getConfig().isDummyRegistryEnabled(); this.remoteRegistries = clusterViewProviderUrls;
clusterViewManager.addObjectToWatch(objectName); } catch (Exception e) { LOGGER.error("Cannot retrieve the object for name {0}", objectName, e);
synchronized(clusterViewManager){ if(clusterViewManager.getPool(objectName) == null) { logger.debug("First lookup on {0}: creation of the pool for its stubs for EJBHome", objectName); Pool<CMIReferenceable<?>, CMIReference> pool = new JPool<CMIReferenceable<?>, CMIReference>( new StubOrProxyFactory(clusterViewManager)); IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); if(poolConfiguration != null) { pool.setPoolConfiguration(poolConfiguration); clusterViewManager.setPool(objectName, pool); homeClass = (Class<? extends EJBHome>) clusterViewManager.getInterface(objectName);