@SuppressWarnings("unchecked") @Override protected CMIReferenceable<T> getCMIReferenceable(final CMIReference cmiReference) throws Exception { return clusterViewManager.getPool(objectName).get(cmiReference); }
/** * Sets the given clue on the given instance. * If no clue is used, this method shouldn't do anything * @param cmiReferenceable the instance to be updated with the clue * @param cmiRef the given clue * @throws PoolException if clue can't be set */ public void setClue(final CMIReferenceable<?> cmiReferenceable, final CMIReference cmiRef) throws PoolException { if (!(cmiReferenceable instanceof CMIReferenceableWrapper)) { throw new PoolException("Cannot set the given clue on the instance"); } // Update the reference ((CMIReferenceableWrapper<?>) cmiReferenceable).setReference(cmiRef); }
@Override protected void onFinallyHook(final String objectName, final CMIReferenceable<T> cmiReferenceable) { try { clusterViewManager.getPool(objectName).release(cmiReferenceable); } catch (Exception e) { logger.debug("Cannot release the reference {0}", cmiReferenceable, e); } }
/** * @param buff * the String buffer to write in. * @param indent * the ident value. */ private void writePoolToXml(final StringBuffer buff, final int indent) { // TODO Auto-generated method stub buff.append(indent); if (poolConfiguration != null) { writeValue(new Integer(poolConfiguration.getMax()).toString(), buff, "<max-size>", "</max-size>"); writeValue(new Integer(poolConfiguration.getMaxWaiters()) .toString(), buff, "<max-waiters>", "</max-waiters>"); writeValue(new Long(poolConfiguration.getTimeout()).toString(), buff, "<timeout>", "</timeout>"); } }
@Override protected void onExceptionHook(final String objectName, final CMIReferenceable<T> cmiReferenceable) throws Exception { try { clusterViewManager.getPool(objectName).discard(cmiReferenceable); } catch (Exception e) { LOGGER.debug("Cannot discard the reference {0}", cmiReferenceable, e); } }
/** * Sets the maximal size of pool of CMIReferenceable for a object with the given name. * @param objectName a name of object * @param maxSize the maximal size of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if no object is bound with the given name * @throws UnsupportedOperationException if the used manager is at client-side */ public void setMaxPoolSize(final String objectName, final Integer maxSize) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); poolConfiguration.setMax(maxSize); ((ServerClusterViewManager) clusterViewManager).getPool(objectName).setPoolConfiguration(poolConfiguration); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
/** * Sets the max waiters of pool of CMIReferenceable for a object with the given name. * @param objectName a name of object * @param maxPoolWaiters the max waiters of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if no object is bound with the given name * @throws UnsupportedOperationException if the used manager is at client-side */ public void setMaxPoolWaiters(final String objectName, final Integer maxPoolWaiters) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); poolConfiguration.setMaxWaiters(maxPoolWaiters); ((ServerClusterViewManager) clusterViewManager).getPool(objectName).setPoolConfiguration(poolConfiguration); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
/** * Sets the pool timeout of CMIReferenceable for a object with the given name. * @param objectName a name of object * @param poolTimeout the timeout of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if no object is bound with the given name * @throws UnsupportedOperationException if the used manager is at client-side */ public void setPoolTimeout(final String objectName, final Long poolTimeout) throws IllegalArgumentException, UnsupportedOperationException { if(!(clusterViewManager instanceof ServerClusterViewManager)) { LOGGER.error("Clients cannot call this method"); throw new UnsupportedOperationException("Clients cannot call this method"); } try { IPoolConfiguration poolConfiguration = clusterViewManager.getPoolConfiguration(objectName); poolConfiguration.setTimeout(poolTimeout); ((ServerClusterViewManager) clusterViewManager).getPool(objectName).setPoolConfiguration(poolConfiguration); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
protected final void updatePool( final DistributedObjectInfo oldDistributedObjectInfo, final DistributedObjectInfo newDistributedObjectInfo) throws ObjectNotFoundException { String objectName = newDistributedObjectInfo.getObjectName(); if (hasPool(objectName)) { IPoolConfiguration newPoolConfiguration = newDistributedObjectInfo .getPoolConfiguration(); if (oldDistributedObjectInfo != null) { IPoolConfiguration oldPoolConfiguration = oldDistributedObjectInfo .getPoolConfiguration(); if (oldPoolConfiguration != null) { if (newPoolConfiguration == null) { newPoolConfiguration = new PoolConfiguration(); } if (!oldPoolConfiguration.equals(newPoolConfiguration)) { getPool(objectName).setPoolConfiguration( newPoolConfiguration); } } } else { if (newPoolConfiguration != null && newPoolConfiguration != new PoolConfiguration()) { getPool(objectName).setPoolConfiguration( newPoolConfiguration); } } } }
/** * Returns the maximal size of pool of CMIReferenceable for a object with the given name. * @param objectName a name of object * @return the maximal size of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if none object has the given name */ public Integer getMaxPoolSize(final String objectName) throws IllegalArgumentException { try { return clusterViewManager.getPoolConfiguration(objectName).getMax(); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
/** * 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()); } }
/** * Returns the pool timeout of CMIReferenceable for a object with the given name. * @param objectName a name of object * @return the timeout of pool of CMIReferenceable for a object with the given name * @throws IllegalArgumentException if none object has the given name */ public Long getPoolTimeout(final String objectName) throws IllegalArgumentException { try { return clusterViewManager.getPoolConfiguration(objectName).getTimeout(); } catch (ObjectNotFoundException e) { LOGGER.error("Object not found: {0}", objectName, e); throw new IllegalArgumentException("Object not found: " + objectName + "\n" + e.getMessage()); } }
@Override protected void onExceptionHook(final String objectName, final CMIReferenceable<T> cmiReferenceable) throws Exception { try { clusterViewManager.getPool(objectName).discard(cmiReferenceable); } catch (Exception e) { logger.debug("Cannot discard the reference {0}", cmiReferenceable, 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); } }
/** * Sets the given clue on the given instance. * If no clue is used, this method shouldn't do anything * @param cmiReferenceable the instance to be updated with the clue * @param cmiRef the given clue * @throws PoolException if clue can't be set */ public void setClue(final CMIReferenceable<?> cmiReferenceable, final CMIReference cmiRef) throws PoolException { if (!(cmiReferenceable instanceof RemoteIIOPCMIReferenceableWrapper)) { throw new PoolException("Cannot set the given clue on the instance"); } // Update the reference ((RemoteIIOPCMIReferenceableWrapper<?>) cmiReferenceable).setReference(cmiRef); }
@SuppressWarnings("unchecked") @Override protected CMIReferenceable<T> getCMIReferenceable(final CMIReference cmiReference) throws Exception { return (CMIReferenceable<T>) clusterViewManager.getPool(objectName).get(cmiReference); }
@Override protected void onFinallyHook(final String objectName, final CMIReferenceable<T> cmiReferenceable) { try { clusterViewManager.getPool(objectName).release(cmiReferenceable); } catch (Exception e) { LOGGER.debug("Cannot release the reference {0}", cmiReferenceable, e); } }
/** * Remove from the factory's pool the bean found in the current invocation * context. * @param invocationContext the context of the current invocation * @throws PoolException if removal is failing */ @SuppressWarnings("unchecked") protected void discard(final EasyBeansInvocationContext invocationContext) throws PoolException { Object target = invocationContext.getTarget(); // factory is a stateful factory ? if (target instanceof EasyBeansSFSB) { // Gets the factory Factory factory = invocationContext.getFactory(); // get pool Pool<EasyBeansSFSB, Long> pool = factory.getPool(); // Bean is a stateful bean EasyBeansSFSB bean = (EasyBeansSFSB) invocationContext.getTarget(); // discard instance pool.discard(bean); } else { this.logger.debug("Instance not discarded as it is not a stateful bean"); } }
/** * Creates an instance of CMIReferenceable with the given hint. * @param cmiReference a clue given by the Pool. Could be null. * @throws PoolException if instance cannot be created. * @return the created instance. */ public CMIReferenceable<?> create(final CMIReference cmiReference) throws PoolException { CMIReferenceable<?> stubOrProxy; try { stubOrProxy = StubOrProxyHelper.download(clusterViewManager, cmiReference); } catch (ProtocolNotFoundException e) { LOGGER.error("Cannot get a CMIReferenceable for " + cmiReference, e); throw new PoolException("Cannot get a CMIReferenceable for " + cmiReference, e); } catch (ObjectNotFoundException e) { LOGGER.error("Cannot get a CMIReferenceable for " + cmiReference, e); throw new PoolException("Cannot get a CMIReferenceable for " + cmiReference, e); } catch (NamingException e) { LOGGER.debug("No CMIReferenceable is bound for " + cmiReference, e); throw new NamingPoolException( "No CMIReferenceable is bound for " + cmiReference, e); } if (expectedType != null && !expectedType.isAssignableFrom(stubOrProxy.getReferencedObject().getClass())) { LOGGER.error("Unexpected type! Required: {0} - Found: {1}", expectedType.getName(), stubOrProxy.getReferencedObject().getClass().getName()); throw new PoolException("Unexpected type! Required: " + expectedType.getName() + " - Found: " + stubOrProxy.getReferencedObject().getClass().getName()); } LOGGER.debug("Adding a new stub/proxy for {0}: {1}", cmiReference, stubOrProxy); return stubOrProxy; }
pool.discard(this.statefulBean); } catch (PoolException pe) { throw new EJBException("Unable to discard the instance", pe);