/**
         * Dispatch request to a appointed socket connection.
         * @param to TransferObject
         * @return Object
         */
        public static object execute(TransferObject to) {
            Object retObject = null;

            if (connectionList == null) {
                initialize();
            }

            String connectionName = to.getConnectionName();

            foreach (SocketConnection connection in connectionList) {
                if (connection.getName().Equals(connectionName)) {
                    if (to.isAsynchronous()) {
                        ExecuteDelegate executeDelegate = delegate(SocketConnection socketConnection, TransferObject transferObject) {
                            return socketConnection.execute(transferObject);
                        };
                        IAsyncResult asyncResult = executeDelegate.BeginInvoke(connection, to, null, null);
                        Future future = new Future(executeDelegate, asyncResult);
                        retObject = future;
                    } else {
                        retObject = connection.execute(to);
                    }
                }
            }

            return retObject;
        }
        public Object execute(TransferObject to) {
            Object resultObject = null;

            resultObject = SocketController.execute(to);

            return resultObject;
        }
        public Object start(TransferObject to) {
            Object resultObject = null;

            String calleeClass = to.getCalleeClass();
            String calleeMethod = to.getCalleeMethod();

            mStateObject.transferObject = to;

            //check if close method, close client
            if (calleeMethod == METHOD_CLOSE) {
                Close(mStateObject);
                return resultObject;
            }

            //set default server call proxy
            if (to.getServerCallProxy() != null) {
                serverCallProxy = to.getServerCallProxy();
            }

            try {
                if (mStateObject.workSocket == null || !mStateObject.workSocket.Connected || closed) {
                    Connect();
                }
                Send(mStateObject);
                resultObject = Receive(mStateObject);

            } catch (Exception e) {
                Logging.LogError("HostIp and Port: [" + hostIp + ":" + hostPort + "]");
                Logging.LogError("Callee Class and Method: [" + calleeClass + "." + calleeMethod + "]");
                Logging.LogError(e.ToString());
                Close(mStateObject);
                throw e;
            }
            return resultObject;
        }
        public Object start(TransferObject to) {
            Object resultObject = null;

            String calleeClass = to.getCalleeClass();
            String calleeMethod = to.getCalleeMethod();

            StateObject stateObject = new StateObject();
            stateObject.transferObject = to;

            try {
                if (Connect(stateObject)) {

                    Send(stateObject);

                    resultObject = Receive(stateObject);
                }
            } catch (Exception e) {
                Logging.LogError("Callee Class and Method: [" + calleeClass + "." + calleeMethod + "]");
                Logging.LogError(e.ToString());
            } finally {
                Close(stateObject);
            }

            return resultObject;
        }
 public static Object execute(TransferObject to) {
     Object retObj = null;
     //for csharp client, server target is Socket.
     target = new SocketServerTarget();
     retObj = target.execute(to);
     return retObj;
 }
        public override Object execute(TransferObject baseto) {
            StandardTransferObject to = (StandardTransferObject)baseto;
            String calleeMethod = to.getCalleeMethod();
            if (calleeMethod.Equals("receiveMessage")) {
                String message = to.getString("message");
                ChatRoomClient.getInstance().receiveMessage(message);
            }

            return null;
        }
Beispiel #7
0
        public Object execute(TransferObject to) {

            String calleeClass = to.getCalleeClass();
            String calleeMethod = to.getCalleeMethod();

            Object retobj = null;
            try {
                Type type = Type.GetType(calleeClass);
                Object instance = Activator.CreateInstance(type);
                MethodInfo method = type.GetMethod(calleeMethod);
                retobj = method.Invoke(instance, new object[] { to });
            } catch (Exception e) {
                Logging.LogError(e.ToString());
            }

            return retobj;
        }
        /**
         * This method handles all outgoing and incoming data.
         * @param to TransferObject
         * @return Object
         */
        public Object execute(TransferObject to) {
		    if(to.isLongConnection()){
			    Monitor.Enter(theLock);
			    try {
				    if(longClientSession == null){
                        longClientSession = new LongClientSession(hostIp, hostPort, timeout, retryCount);
				    }
				    return longClientSession.start(to);
			    } finally {
                    Monitor.Exit(theLock);
			    }
		    }else{
			    if(shortClientSession == null){
                    shortClientSession = new ShortClientSession(hostIp, hostPort, timeout, retryCount);
			    }
			    return shortClientSession.start(to);
		    }
	    }
        private void execute(TransferObject to) {

            String calleeClassName = to.getCalleeClass();

            //Check default proxy, don't need reflection.
            if (calleeClassName.Equals(TransferObject.DEFAULT_PROXY)) {
                if (serverCallProxy != null) {
                    serverCallProxy.execute(to);
                }
            } else {
                String calleeMethod = to.getCalleeMethod();
                Type type = Type.GetType(calleeClassName);
                Object instance = Activator.CreateInstance(type);
                MethodInfo method = type.GetMethod(calleeMethod);
                method.Invoke(instance, new object[] { to });
            }

        }
Beispiel #10
0
        public static byte[] transferObjectToByteArray(TransferObject to) {
    	    // out
		    byte[] toByteArray = to.getByteData();
		    byte[] sendData = null;
		    // if compress flag is true
            if (to.isCompress()) {
			    sendData = TransferUtil.getOutputByCompress(toByteArray);
		    } else {
			    sendData = TransferUtil.getOutputByNormal(toByteArray);
		    }

            //set long connection flag
            if (to.isLongConnection()) {
                sendData[0] |= TransferObject.LONGCONNECTION_FLAG;
            }

            //set new version flag
            if (to.isNewVersion()) {
                sendData[0] |= TransferObject.NEWVERSION_FLAG;
            }

            byte[] newData = new byte[sendData.Length + TatalaFlag.Length];
            Array.Copy(TatalaFlag, 0, newData, 0, TatalaFlag.Length);
            Array.Copy(sendData, 0, newData, TatalaFlag.Length, sendData.Length);
            sendData = newData;

		    return sendData;
        }
Beispiel #11
0
 public virtual Object execute(TransferObject to) {
     Logging.LogError("This is DefaultProxy. You need extend it by specific proxy.");
     return null;
 }