All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.Extensibility.Client.ClientSurrogateObject Maven / Gradle / Ivy

package Alachisoft.NCache.Common.Extensibility.Client;

import Alachisoft.NCache.Common.Extensibility.Client.RPC.*;
import Alachisoft.NCache.Common.Extensibility.Client.RPC.Impl.BroadcastingMethodArgumentPartitioner;
import Alachisoft.NCache.Common.Extensibility.Client.RPC.Impl.MultiPartitionMethodCall;
import Alachisoft.NCache.Common.Extensibility.SurrogateObjectBase;
import com.google.common.reflect.TypeToken;

import java.lang.reflect.Type;

public class ClientSurrogateObject extends SurrogateObjectBase implements IClientSurrogateObject {
    private final TypeToken typeToken = new TypeToken(getClass()) {
    };
    private final Type type = typeToken.getType();  // or getRawType() to return Class
    protected IRPCCallBuilder _callBuilder;
    protected IRPCTransport _transport;
    protected String _objectUID;
    protected Object[] _constructorParams;
    private IMethodArgumentPartitioner _methodArgumentPartitioner = BroadcastingMethodArgumentPartitioner.getInstance();

    public ClientSurrogateObject(IRPCCallBuilder rpcCallBuilder, IRPCTransport transport, Object[] arguements, String objectUID) {
        super(objectUID);
        Initialize(rpcCallBuilder, transport, arguements, objectUID);
    }

    public ClientSurrogateObject(IRPCCallBuilder rpcCallBuilder, IRPCTransport transport, Object[] arguements) {
        Initialize(rpcCallBuilder, transport, arguements, super.getObjectUID());
    }

    public Type getType() {
        return type;
    }

    private void Initialize(IRPCCallBuilder rpcCallBuilder, IRPCTransport transport, Object[] arguments, String objectUID) {
        this._objectUID = objectUID;
        this._callBuilder = rpcCallBuilder;
        this._transport = transport;
        this._constructorParams = arguments;
    }

    public final void CreateInstance() {
        try {
            InitializeInstance(this._constructorParams);
        } catch (Exception e) {
        }
    }

    public final  TResult InvokeMethod(String method, int overload, Object[] arguments, boolean isStatic, IMethodArgumentPartitioner methodAgrumentPartitioner, IResponseConsolidator consolidator) throws Exception {
        methodAgrumentPartitioner = (methodAgrumentPartitioner != null) ? methodAgrumentPartitioner : _methodArgumentPartitioner;
        IRPCMethodCall methodCall = this._callBuilder.BuildMethodCall(null, method, overload, isStatic, arguments, _objectUID, methodAgrumentPartitioner, consolidator);

        return this._transport.ExecuteMethod(methodCall);
    }

    public final  TResult InvokeMultiPartitionMethod(String method, int overlaod, Object[] arguments, IResponseConsolidator consolidator) throws Exception {
        MultiPartitionMethodCall methodCall = this._callBuilder.BuildMultipartionMethodCall(method, overlaod, arguments, _objectUID);
        methodCall.setConsolidator(consolidator);
        return this._transport.ExecuteMethod(methodCall);
    }

    public final  void InvokePropertySetter(String property, TValue argument, IResponseConsolidator consolidator) throws Exception {
        IRPCPropertyCall propertyCall = this._callBuilder.BuildPropertySetterCall(property, argument, _objectUID);
        propertyCall.setConsolidator(consolidator);
        this._transport.ExecuteProperty(propertyCall);
    }

    public final  TValue InvokePropertyGetter(String property, IMethodArgumentPartitioner methodAgrumentPartitioner, IResponseConsolidator consolidator) throws Exception {
        IRPCPropertyCall propertyCall = this._callBuilder.BuildPropertyGetterCall(property, _objectUID);
        propertyCall.setConsolidator(consolidator);
        return this._transport.ExecuteProperty(propertyCall);
    }

    @Override
    public void InitializeInstance(Object[] args) throws Exception {
        IRPCConstructorCall constructor = this._callBuilder.BuildConstructorCall(type.getClass(), _objectUID, args);
        this._transport.ExecuteConstructor(constructor);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy