Class DynamicSmartStub

java.lang.Object
com.gigaspaces.lrmi.DynamicSmartStub
All Implemented Interfaces:
ProxyInvocationHandler, ILRMIProxy, Externalizable, Serializable, InvocationHandler, Remote

public class DynamicSmartStub extends Object implements ProxyInvocationHandler, InvocationHandler, Serializable, Remote, Externalizable, ILRMIProxy
This class represents dynamic smart stub of underlying transport protocol. Due the dynamic proxy Proxy this class serves as Interceptor of invoked methods. The invoked method injected by dynamic-proxy delegates to the direct reference reflection call of exported object, only in case this DynamicSmartStub still handles a direct reference of exported object getLocalObjImpl().

If DynamicSmartStub is serializing, as part writeExternal(java.io.ObjectOutput) method the getLocalObjImpl() will be exported to the underlying transport protocol. The serialization process is an indication for DynamicSmartStub about exiting out side from local JVM.
On deserialization the DynamicSmartStub will try to acquire the direct localObject reference from the underlying transport protocol. If direct reference wasn't acquired, it means the stub instance is not in local JVM. Every future injected method will be called remotely.

Since:
5.2
Author:
Igor Goldenberg
See Also:
  • Field Details

    • markProxyAsClosed

      public static final transient ThreadLocal<Boolean> markProxyAsClosed
  • Constructor Details

    • DynamicSmartStub

      public DynamicSmartStub()
  • Method Details

    • invoke

      public Object invoke(Object proxy, Method method, Object[] args) throws Throwable
      Needed for standard java dynamic proxy.
      Specified by:
      invoke in interface InvocationHandler
      Throws:
      Throwable
    • invoke

      public Object invoke(Object proxy, IMethod method, Object[] args) throws Throwable
      Processes a method invocation on a proxy instance and returns the result. This method will be invoked on an invocation handler when a method is invoked on a proxy instance that it is associated with.
      Specified by:
      invoke in interface ProxyInvocationHandler
      Parameters:
      proxy - the proxy instance that the method was invoked on
      method - the IMethod instance corresponding to the interface method invoked on the proxy instance. The declaring class of the IMethod object will be the interface that the method was declared in, which may be a superinterface of the proxy interface that the proxy class inherits the method through.
      args - an array of objects containing the values of the arguments passed in the method invocation on the proxy instance, or null if interface method takes no arguments. Arguments of primitive types are wrapped in instances of the appropriate primitive wrapper class, such as java.lang.Integer or java.lang.Boolean.
      Returns:
      the value to return from the method invocation on the proxy instance. If the declared return type of the interface method is a primitive type, then the value returned by this method must be an instance of the corresponding primitive wrapper class; otherwise, it must be a type assignable to the declared return type. If the value returned by this method is null and the interface method's return type is primitive, then a NullPointerException will be thrown by the method invocation on the proxy instance. If the value returned by this method is otherwise not compatible with the interface method's declared return type as described above, a ClassCastException will be thrown by the method invocation on the proxy instance.
      Throws:
      Throwable - the exception to throw from the method invocation on the proxy instance. The exception's type must be assignable either to any of the exception types declared in the throws clause of the interface method or to the unchecked exception types java.lang.RuntimeException or java.lang.Error. If a checked exception is thrown by this method that is not assignable to any of the exception types declared in the throws clause of the interface method, then an UndeclaredThrowableException containing the exception that was thrown by this method will be thrown by the method invocation on the proxy instance.
      See Also:
    • invokeRemote

      protected Object invokeRemote(Object proxy, IMethod method, Object[] args) throws Throwable
      performs remote invocation method
      Throws:
      Throwable
    • getInvocationHandler

      protected MethodCachedInvocationHandler getInvocationHandler() throws RemoteException
      returns the initialized remote InvocationHandler
      Throws:
      RemoteException
    • getRemoteObjID

      public long getRemoteObjID()
      Returns:
      the remote objID
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • readExternal

      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
      ClassNotFoundException
    • getLocalObjImpl

      public Object getLocalObjImpl()
      Returns:
      The instance of local object impl, or null if this Stub doesn't exist in local exported VM
    • extractDynamicSmartStubFrom

      public static DynamicSmartStub extractDynamicSmartStubFrom(Object obj)
      Parameters:
      obj - the object to extract DynamicSmartStub instance.
      Returns:
      the extracted DynamicSmartStub instance or null supplied object is not DynamicSmartStub invocation handler and not Proxy.
    • isCollocated

      public boolean isCollocated()
      Returns:
      true if this instance of DynamicSmartStub is collocated with exported endpoint object, otherwise false if this stub is remote.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      the HashCode of this DynamicSmartStub
    • equals

      public boolean equals(Object obj)
      Equals the DynamicSmartStub instances by direct obj reference if the stubs in local VM, otherwise equals by remoteObjId
      Overrides:
      equals in class Object
    • isUnexported

      public boolean isUnexported()
      Returns:
      true if DynamicSmartStub was closed
    • closeProxy

      public void closeProxy()
      Description copied from interface: ILRMIProxy
      Close the underline proxy connection and resources, this proxy will no longer be usable.
      Specified by:
      closeProxy in interface ILRMIProxy
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface ILRMIProxy
      Returns:
      true if this proxy is closed.
    • isRemote

      public boolean isRemote()
      Specified by:
      isRemote in interface ILRMIProxy
      Returns:
      whether this proxy is connected to a remote stub
    • getServicePlatformLogicalVersion

      public PlatformLogicalVersion getServicePlatformLogicalVersion()
      Specified by:
      getServicePlatformLogicalVersion in interface ILRMIProxy
      Returns:
      returns the logical version of the service
    • getGeneratedTraffic

      public long getGeneratedTraffic()
      Specified by:
      getGeneratedTraffic in interface ILRMIProxy
      Returns:
      entire traffic generated by this proxy in bytes, this number is not necessarily monotonic as each connection in the stub holds this data per connection, once this connection is disconnected/reconnected this data is reseted.
    • getReceivedTraffic

      public long getReceivedTraffic()
      Specified by:
      getReceivedTraffic in interface ILRMIProxy
      Returns:
      entire traffic received by this proxy in bytes this number is not necessarily monotonic as each connection in the stub holds this data per connection, once this connection is disconnected/reconnected this data is reseted.
    • getConnectionUrl

      public String getConnectionUrl()
      Returns the connectionURL of exported remote object.
      Specified by:
      getConnectionUrl in interface ILRMIProxy
      Returns:
      the unique connectionURL of exported remote object. This URL contains [Protocol]://[ServerEndPointIP:Port]/[RemoteObjectUID]_[StubSeqID] Example: NIO://192.168.0.100:61754/1164059001211_0
    • getRemoteProcessId

      public long getRemoteProcessId()
      Specified by:
      getRemoteProcessId in interface ILRMIProxy
      Returns:
      the process id of the stub
    • getRemoteHostName

      public String getRemoteHostName()
      Specified by:
      getRemoteHostName in interface ILRMIProxy
      Returns:
      return the host name of the stub
    • getRemoteHostAddress

      public String getRemoteHostAddress()
      Specified by:
      getRemoteHostAddress in interface ILRMIProxy
      Returns:
      return the host address of the stub
    • getRemoteNetworkAddress

      public InetSocketAddress getRemoteNetworkAddress()
      Specified by:
      getRemoteNetworkAddress in interface ILRMIProxy
      Returns:
      the ip address + port of the stub
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getStubId

      public StubId getStubId()
      Specified by:
      getStubId in interface ILRMIProxy
      Returns:
      the stub id
    • disable

      public void disable() throws RemoteException
      Description copied from interface: ILRMIProxy
      Force this stub to be disabled (disconnected from its target)
      Specified by:
      disable in interface ILRMIProxy
      Throws:
      RemoteException
    • enable

      public void enable() throws RemoteException
      Description copied from interface: ILRMIProxy
      Removes state of any previously called ILRMIProxy.disable()
      Specified by:
      enable in interface ILRMIProxy
      Throws:
      RemoteException
    • overrideMethodsMetadata

      public void overrideMethodsMetadata(Map<String,LRMIMethodMetadata> methodsMetadata)
      Description copied from interface: ILRMIProxy
      Overrides the LRMI methods metadata. Can only be used before first invocation.
      Specified by:
      overrideMethodsMetadata in interface ILRMIProxy
    • throwProxyClosedExeption

      public static void throwProxyClosedExeption(String connectionUrl) throws ProxyClosedException
      Throws:
      ProxyClosedException
    • getMonitoringDetails

      public static LRMIOutboundMonitoringDetailsImpl getMonitoringDetails()
    • finalize

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • simulatedDisconnectionByPID

      public static void simulatedDisconnectionByPID(int pid)
    • simulatedReconnectionByPID

      public static void simulatedReconnectionByPID(int pid)