/** * Construct a new handler of {@link CMIProxy}. * @param objectName the object name * @param interfaceName the name of the interface implemented by the handled proxy * @param cmiProxy the cmi proxy */ public CMIProxyHandleImpl(final String objectName, final String interfaceName, final CMIProxy cmiProxy) { this.objectName = objectName; this.cmiProxy = cmiProxy; this.interfaceName = interfaceName; serializedProxy = CMIProxySerializer.serialize(cmiProxy); }
@Override public String toString() { return serverRef.getProviderURL()+"/"+objectName; }
/** * Constructs an instance of CMIReference. * @param protocol a name of protocol to access at the clustered object * @param providerURL a provider URL to access at the clustered object * @param objectName a name of object * @throws MalformedURLException if the URL is malformed * @throws UnknownHostException if the provided address can not be determined */ public CMIReference(final String protocol, final String providerURL, final String objectName) throws MalformedURLException, UnknownHostException { serverRef = new ServerRef(protocol, providerURL); this.objectName = objectName; }
private Object writeReplace() throws ObjectStreamException { CMIReference ref = getReference(); if(ref.getServerRef().getProtocol().equals("iiop")) { String ior; try { ior = Utility.remote_to_string(getReferencedObject()); } catch (NamingException e) { throw new InvalidObjectException("Cannot get the ior from the stub " + getReferencedObject()); } return new RemoteCMIReferenceableWrapper<T>(ref, ior); } else { return this; } }
@SuppressWarnings("unchecked") private Object readResolve() throws ObjectStreamException { CMIReference ref = getReference(); if(ref.getServerRef().getProtocol().equals("iiop")) { T remote; try { remote = (T) Utility.string_to_remote(ior); } catch (NamingException e) { throw new InvalidObjectException("Cannot get the stub from the ior " + ior); } return new RemoteCMIReferenceableWrapper<T>(ref, remote); } else { return this; } }
/** * 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 = CMIConfig.getBindNameForProvider(); 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; }
/** * Binds a dummy registry to enable the load-balancing of JNDI accesses to unclustered objects. * @param serverRef a reference on the local registry */ private void bindDummyRegistry(final ServerRef serverRef) { String bindName = CMIConfig.getBindNameForDummyRegistry(); // Create an instance of CMIReference for this object CMIReference cmiReference = new CMIReference(serverRef, bindName); addObjectInstance(clusteredObjectInfoForDummyRegistry, cmiReference); }
/** * Checks if the given object with the given clue is matching. * @param cmiReferenceable given object against which the check should be done. * @param cmiReference the object used as clue to check the matching. * @return true if it is matching, else false. */ public boolean isMatching(final CMIReferenceable cmiReferenceable, final CMIReference cmiReference) { LOGGER.debug("{0} == {1} ?", cmiReferenceable.getReference(), cmiReference); return cmiReferenceable.getReference().equals(cmiReference); }
/** * 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 List<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; }
public static Remote string_to_remote(final String ior) throws NamingException { return (Remote) PortableRemoteObject.narrow( getORB().string_to_object(ior), Remote.class); } }
protected CMIReferenceable<?> getCMIReferenceable(final CMIReference cmiRef, final Object stubOrProxy) { return new CMIReferenceableWrapper<Object>(cmiRef, stubOrProxy); } }
@Override public boolean equals(final Object obj) { if(obj == null || !(obj instanceof CMIReferenceable)) { return false; } CMIReferenceable<?> cmiReferenceable = (CMIReferenceable<?>) obj; return referencedObject.equals(cmiReferenceable.getReferencedObject()); }
@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 int hashCode() { return serverRef.hashCode()+objectName.hashCode(); }
public CMIProxy getCMIProxy() throws RemoteException { if(cmiProxy == null) { if(serializedProxy == null) { throw new RemoteException("The handle is empty !"); } Object object = CMIProxySerializer.unserialize(this); if(object == null) { throw new RemoteException("Cannot unserialize the EJBHome"); } cmiProxy = (CMIProxy) object; } return cmiProxy; }
/** * 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 */ public synchronized T choose(final List<T> cmiReferences) throws NoLoadBalanceableException { if (cmiReferences.size() == 0) { LOGGER.error("The given list is empty"); throw new NoLoadBalanceableException("The given list is empty"); } // 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 lbPolicy.choose(cmiReferences); }
serverRefs.add(new ServerRef(protocol, providerURL)); } catch (MalformedURLException e) { logger.error("The following provider URL is malformed {0}", providerURL);
public void unbind(final String name) throws NamingException { LOGGER.debug("unbind {0}", name); if(serverModeEnabled) { LOGGER.debug("Server mode enabled"); // Verify that replication is activated if(replicationEnabled) { // Tests if the object is clustered boolean isClustered = clusterViewManager.isClustered(name); if(isClustered) { LOGGER.debug("{0} is clustered", name); ((ServerClusterViewManager) clusterViewManager).removeCMIReference( new CMIReference(localRegistry, name)); } } localContext.unbind(name); } else { LOGGER.warn("Cannot unbind because server mode is not activated."); } }
public CMIProxyHandle updateHttpSession() { CMIProxyHandle cmiProxyHandle = null; if (httpBound) { serializedProxy = CMIProxySerializer.serialize(cmiProxy); try { cmiProxyHandle = (CMIProxyHandle) clone(); } catch (CloneNotSupportedException e) { e.printStackTrace(); } // when we call setAttribute on the httpSession httpSession.setAttribute(attributeName, cmiProxyHandle); } return cmiProxyHandle; }
public static String remote_to_string(final Remote remote) throws NamingException { Servant servant = (Servant) Util.getTie(remote); org.omg.CORBA.Object o = servant._this_object(); return getORB().object_to_string(o); }