Package test.common

Examples of test.common.Message


    public Message sendRequest(String operation, String[] body) throws IOException {
        return sendRequest(operation, body, DEFAULT_TIMEOUT);
    }
   
    public Message sendRequest(String operation, String[] body, int timeout) throws IOException {
        Message request = new Message(operation, body);
        sendMessage(request);
        Message reply = receiveMessage(request.getId(), timeout);
       
        if (VoidMessage.OPERATION.equals(reply.getType())) {
            return null;
        } else if (ErrorMessage.OPERATION.equals(reply.getType())) {
            StringBuffer buf = new StringBuffer();
            for (int i = 0; i < reply.getBody().length; i++) {
                buf.append(reply.getBody()[i]);
            }
            throw new RuntimeException(buf.toString());
        }
       
        return reply;
View Full Code Here


        if (args.length > 1) {
            msg = new String[args.length - 2];
            System.arraycopy(args, 2, msg, 0, msg.length);
        }
        try {
            Message reply = client.sendRequest(args[1], msg, 1000);
            if (reply != null) {
                if (reply.getBody().length == 0) {
                    System.out.println("Received " + reply.getType() + " from server.");
                } else {
                    System.out.println("Received " + reply.getType() + " from server:");
                    for (int i = 0; i < reply.getBody().length; i++) {
                        System.out.println(reply.getBody()[i]);
                    }
                }
            }
        } catch (Exception ex) {
            System.err.println("Operation " + args[1] + " failed:");
View Full Code Here

            return "ping";
        }
       
        public Message execute(String[] msgBody) {
            System.out.println("Ping");
            return new Message("pong");
        }
View Full Code Here

        public Message execute(String[] msgBody) {
            System.out.println("Received echo message:");
            for (int i = 0; i < msgBody.length; i++) {
                System.out.println(msgBody[i]);
            }
            return new Message(OPERATION, msgBody);
        }
View Full Code Here

        shutdown = true;
    }
   
    public void run() {
        do {
            Message request = null;
            try {
                request = receiveMessage(null, -1);
            } catch (IOException ioe) {
                System.err.println("Exception while receiving message: " + ioe);
                continue;
            }
            MessageHandler handler = getMessageHandler(request);
            Throwable error = null;
           
            if (handler == null) {
                try {
                    String id = request.getId();
                    Message reply = unhandledMessage(request);
                    sendReply(reply, id);
                } catch (Throwable t) {
                    error = t;
                }
            } else {
                try {
                    Message reply = handler.execute(request.getBody());
                    sendReply(reply, request.getId());
                } catch (Throwable t) {
                    error = t;
                }
            }
View Full Code Here

TOP

Related Classes of test.common.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.