/** * Returns a string representation for a proxy that uses this invocation handler. **/ @Override protected String proxyToString(final Object proxy) { return "POJOProxy[" + super.proxyToString(proxy) + "]"; }
/** * Returns a string representation for a proxy that uses this invocation * handler. **/ @Override protected String proxyToString(final Object proxy) { return "EJBHomeProxy[" + super.proxyToString(proxy) + ", remoteClass:" + remoteClass.getName() + ", ejbMetada:" + ejbMetaData + "]"; }
@Override protected void checkInitialized() throws CMIInvocationHandlerException { if(classLoader == null) { try { classLoader = Thread.currentThread().getContextClassLoader(); } catch(Exception e) { throw new POJOInvocationHandlerException( "Cannot retrieve the classloader for object with name " + objectName, e); } } }
} catch (ObjectNotFoundException e) { logger.error("Cannot retrieve the interface for object with name " + objectName, e); throw new CMIInvocationHandlerException( "Cannot retrieve the interface for object with name " + objectName, e); registerCMIManagedObject(); checkInitialized(); return invokeObjectMethod(proxy, method, args); return invokeCMIProxy( methodName.substring(0, methodName.length() - 4), proxy); return invokeRemoteMethod(proxy, method, args);
/** * Handles remote methods. **/ @Override protected Object invokeRemoteMethod( final Object proxy, final Method method, final Object... args) throws Throwable { // Use the same classloader that during the creation of this object ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); setClassLoader(oldClassLoader); try { // Generate a requestId RequestId requestId = new RequestId(sessionId, requestNb); // Set this request in the current context HACurrent.getHACurrent().putNextReq(requestId); Object result = super.invokeRemoteMethod(proxy, method, args); // Update the request number now that all is OK requestNb++; if (onFailover) { onFailover = false; HACurrent.getHACurrent().setOnFailover(false); } return result; } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
/** * Handles remote methods. * @throws POJOInvocationHandlerException if a server cannot be chosen * @throws Throwable if the invoked method throws an exception **/ @Override protected Object invokeRemoteMethod(final Object proxy, final Method method, final Object... args) throws POJOInvocationHandlerException, Throwable { // Use the same classloader that during the creation of this object ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(classLoader); setClassLoader(oldClassLoader); try { return super.invokeRemoteMethod(proxy, method, args); } finally { Thread.currentThread().setContextClassLoader(oldClassLoader); } }
/** * Handle the invocation of methods defined in the interface {@link CMIProxy}. * @param methodName the method name without the suffix _CMI * @param proxy the proxy to use * @return the result of invocation * @throws CMIInvocationHandlerException */ private Object invokeCMIProxy(final String methodName, final Object proxy) throws CMIInvocationHandlerException { if(methodName.equals("getObjectName")) { return objectName; } else if(methodName.equals("getInterface")) { return itf; } else if(methodName.equals("getProtocolName")) { return protocolName; } else if(methodName.equals(getHandleMethodName())) { return getHandle((CMIProxy) proxy); } else if(methodName.equals("getCurrentCMIRef")) { return currentRef; } else if(methodName.equals("isCMIRefKept")) { return keepCurrentRef; } throw new CMIInvocationHandlerException( "CMIProxy doesn't define the method " + methodName); }
@SuppressWarnings("unchecked") @Override protected CMIReferenceable<Object> getCMIReferenceable( final CMIReference cmiReference) throws POJOInvocationHandlerException { try { return (CMIReferenceable<Object>) StubOrProxyHelper.download(clusterViewManager, cmiReference); } catch (ProtocolNotFoundException e) { logger.error("Cannot get a CMIReferenceable for " + cmiReference, e); throw new POJOInvocationHandlerException("Cannot get a CMIReferenceable for " + cmiReference, e); } catch (ObjectNotFoundException e) { logger.error("Cannot get a CMIReferenceable for " + cmiReference, e); throw new POJOInvocationHandlerException("Cannot get a CMIReferenceable for " + cmiReference, e); } catch (NamingException e) { logger.debug("No CMIReferenceable is bound for " + cmiReference, e); throw new POJOInvocationHandlerException( "No CMIReferenceable is bound for " + cmiReference, e); } }
/** * Return a stub of {@link EJBObject} wrapped with its CMIReference. * @param proxy a CMI proxy * @param method a create (or find) method * @param args method arguments * @return a wrapper containing a stub of EJBObject and its CMIReference * @throws Throwable if the stub cannot be downloaded */ public CMIReferenceableWrapper<EJBObject> getWrappedEJBObject( final Object proxy, final Method method, final Object... args) throws Throwable { // Get a stub of EJBObject EJBObject ejbObject = (EJBObject) super.invokeRemoteMethod(proxy, method, args); // Wrap it with its associated CMIReference return new CMIReferenceableWrapper<EJBObject>(getCurrentRef().getReference(), ejbObject); }
/** * 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; }
/** * @param invocationHandler */ private void unregisterCMIInvocationHandler(final CMIInvocationHandler<?> invocationHandler) { this.service.unregisterDispatcher(invocationHandler.getCMIManagedObjectId()); this.objects.remove(invocationHandler); }
@Override protected void onExceptionHook( final String objectName, final CMIReferenceable<Object> cmiReferenceable) throws Throwable { setCurrentRef(null); // Set onFailover onFailover = true; // Propagate onFailover status to the server HACurrent.getHACurrent().setOnFailover(true); }
private void registerCMIManagedObject() { dispatcher = clusterViewManager.getEventDispatcher(); if(dispatcher != null) { cmiManagedObjectId = "/cmi/" + objectName + "/" + protocolName + "/" + id++; // Register to event component. CMIEventComponent eventComponent = getComponent(CMIEventComponent.class); if (eventComponent != null) { eventComponent.registerCMIManagedObject(this, this.dispatcher); } } }
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); } }
/** * Returns a string representation for a proxy that uses this invocation * handler. **/ @Override protected String proxyToString(final Object proxy) { return "EJBObjectProxy[" + super.proxyToString(proxy) + ", homeClass:" + homeClass.getName() + ", ejbHomeProxy:" + ejbHomeProxy + "]"; }
/** * Returns a string representation for a proxy that uses this invocation * handler. **/ @Override protected String proxyToString(final Object proxy) { return "HAEJBObjectProxy[" + super.proxyToString(proxy) + ", homeClass:" + homeClass.getName() + ", ejbHomeProxy:" + ejbHomeProxy + ", sessionId:" + sessionId + ", requestNb:" + requestNb + ", createMethodWrapper:" + createMethodWrapper + ", onFailover:" + onFailover + "]"; }
@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); } } }
private void registerCMIInvocationHandler( final CMIInvocationHandler<?> invocationHandler, final IEventDispatcher dispatcher) { this.service.registerDispatcher(invocationHandler.getCMIManagedObjectId(), dispatcher); this.objects.add(invocationHandler); }
/** * Returns a string representation for a proxy that uses this invocation * handler. **/ @Override protected String proxyToString(final Object proxy) { return "HAEJBHomeProxy[" + super.proxyToString(proxy) + ", remoteClass:" + remoteClass.getName() + ", ejbMetada:" + ejbMetaData + "]"; }
/** * Handles java.lang.Object methods. **/ private Object invokeObjectMethod(final Object proxy, final Method method, final Object... args) { String name = method.getName(); if (name.equals("hashCode")) { return Integer.valueOf(hashCode()); } else if (name.equals("equals")) { Object obj = args[0]; boolean b = proxy == obj || (obj != null && Proxy.isProxyClass(obj.getClass()) && equals(Proxy.getInvocationHandler(obj))); return Boolean.valueOf(b); } else if (name.equals("toString")) { return proxyToString(proxy); } else { logger.error("unexpected Object method: {0}", method); throw new IllegalArgumentException("unexpected Object method: " + method); } }