Package com.betfair.cougar.transport.api.protocol

Examples of com.betfair.cougar.transport.api.protocol.CougarObjectOutput


                        "This Client is not connected to a server so this call cannot be completed!")));
            } else {
                try {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte protocolVersion = CougarProtocol.getProtocolVersion(session);
                    final CougarObjectOutput out = objectIOFactory.newCougarObjectOutput(baos, protocolVersion);

//                    addObserver(correlationId, def.getReturnType(), observer);
                    marshaller.writeInvocationRequest(new InvocationRequest() {

                        @Override
                        public Object[] getArgs() {
                            return args;
                        }

                        @Override
                        public ExecutionContext getExecutionContext() {
                            return ctx;
                        }

                        @Override
                        public OperationKey getOperationKey() {
                            return def.getOperationKey();
                        }

                        @Override
                        public Parameter[] getParameters() {
                            return def.getParameters();
                        }

                        @Override
                        public TimeConstraints getTimeConstraints() {
                            return timeConstraints;
                        }
                    }, out, getIdentityResolver(), protocolVersion);
                    out.close();

                    ((RequestResponseManager) session.getAttribute(RequestResponseManager.SESSION_KEY)).sendRequest(baos.toByteArray(), new RequestResponseManager.ResponseHandler() {
                        @Override
                        public void responseReceived(ResponseMessage message) {
                            CougarObjectInput in = objectIOFactory.newCougarObjectInput(new ByteArrayInputStream(message.getPayload()), CougarProtocol.getProtocolVersion(session));
View Full Code Here


        }
        return null;
    }

    protected boolean writeSuccessResponse(SocketTransportRPCCommand command, ExecutionResult result) {
        CougarObjectOutput out = command.getOutput();
        try {
            synchronized (out) {
                marshaller.writeInvocationResponse(new InvocationResponseImpl(result.getResult(), null), out, CougarProtocol.getProtocolVersion(command.getSession()));
                out.flush();
            }
            return true;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Unable to stream response to client", e);
            return false;
View Full Code Here

    @Override
    protected void writeErrorResponse(SocketTransportCommand command, ExecutionContextWithTokens context, CougarException e) {
        if (command instanceof SocketTransportRPCCommand) {
            SocketTransportRPCCommand rpcCommand = (SocketTransportRPCCommand) command;
            incrementErrorsWritten();
            CougarObjectOutput out = rpcCommand.getOutput();
            try {
                synchronized (out) {
                    marshaller.writeInvocationResponse(new InvocationResponseImpl(null, e), out, CougarProtocol.getProtocolVersion(command.getSession()));
                    out.flush();
                }
            } catch (Exception ex) {
                //An unrecoverable exception, lest we end up in an infinite loop
                logger.log(Level.SEVERE, "Unable to stream error response to client", ex);
            } finally {
View Full Code Here

                        "This Client is not connected to a server so this call cannot be completed!")));
            } else {
                try {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    byte protocolVersion = CougarProtocol.getProtocolVersion(session);
                    final CougarObjectOutput out = objectIOFactory.newCougarObjectOutput(baos, protocolVersion);

//                    addObserver(correlationId, def.getReturnType(), observer);
                    marshaller.writeInvocationRequest(new InvocationRequest() {

                        @Override
                        public Object[] getArgs() {
                            return args;
                        }

                        @Override
                        public ExecutionContext getExecutionContext() {
                            return ctx;
                        }

                        @Override
                        public OperationKey getOperationKey() {
                            return def.getOperationKey();
                        }

                        @Override
                        public Parameter[] getParameters() {
                            return def.getParameters();
                        }

                        @Override
                        public TimeConstraints getTimeConstraints() {
                            return timeConstraints;
                        }
                    }, out, getIdentityResolver(), protocolVersion);
                    out.close();

                    ((RequestResponseManager) session.getAttribute(RequestResponseManager.SESSION_KEY)).sendRequest(baos.toByteArray(), new RequestResponseManager.ResponseHandler() {
                        @Override
                        public void responseReceived(ResponseMessage message) {
                            CougarObjectInput in = objectIOFactory.newCougarObjectInput(new ByteArrayInputStream(message.getPayload()), CougarProtocol.getProtocolVersion(session));
View Full Code Here

        return bb;
    }

    public static void writeEventMessageToSession(IoSession session, Object obj, CougarObjectIOFactory objectIOFactory) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        CougarObjectOutput out = objectIOFactory.newCougarObjectOutput(baos, CougarProtocol.getProtocolVersion(session));
        out.writeObject(obj);
        out.flush();

        session.write(new EventMessage(baos.toByteArray()));
    }
View Full Code Here

                                        }
                                        Map<Byte, EventMessage> serialisedUpdatesByProtocolVersion = new HashMap<Byte, EventMessage>();
                                        long updateId = heapState.getNextUpdateId();
                                        for (Byte version : protocolVersions) {
                                            ByteArrayOutputStream baos = new ByteArrayOutputStream();
                                            CougarObjectOutput out = objectIOFactory.newCougarObjectOutput(baos, version);
                                            out.writeObject(new HeapDelta(heapState.getHeapId(), updateId, updatesThisBatch));
                                            out.flush();
                                            serialisedUpdatesByProtocolVersion.put(version, new EventMessage(baos.toByteArray()));
                                        }
                                        // now write these out for each session
                                        for (IoSession session : heapState.getSessions()) {
                                            nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, session, "Sending heap delta of size %s and with updateId = %s for heapId = %s", updatesThisBatch.size(), updateId, heapState.getHeapId());
View Full Code Here

        }
        return null;
    }

    protected boolean writeSuccessResponse(SocketTransportRPCCommand command, ExecutionResult result) {
        CougarObjectOutput out = command.getOutput();
        try {
            synchronized (out) {
                marshaller.writeInvocationResponse(new InvocationResponseImpl(result.getResult(), null), out, CougarProtocol.getProtocolVersion(command.getSession()));
                out.flush();
            }
            return true;
        } catch (Exception e) {
            logger.log(Level.SEVERE, "Unable to stream response to client", e);
            return false;
View Full Code Here

    @Override
    protected void writeErrorResponse(SocketTransportCommand command, ExecutionContextWithTokens context, CougarException e) {
        if (command instanceof SocketTransportRPCCommand) {
            SocketTransportRPCCommand rpcCommand = (SocketTransportRPCCommand) command;
            incrementErrorsWritten();
            CougarObjectOutput out = rpcCommand.getOutput();
            try {
                synchronized (out) {
                    marshaller.writeInvocationResponse(new InvocationResponseImpl(null, e), out, CougarProtocol.getProtocolVersion(command.getSession()));
                    out.flush();
                }
            } catch (Exception ex) {
                //An unrecoverable exception, lest we end up in an infinite loop
                logger.log(Level.SEVERE, "Unable to stream error response to client", ex);
            } finally {
View Full Code Here

            ((IoHandler) session.getAttribute(RequestResponseManager.SESSION_KEY)).messageReceived(session, message);
        }
        else if (message instanceof RequestMessage) {
            RequestMessage req = (RequestMessage) message;

            final CougarObjectOutput out = objectIOFactory.newCougarObjectOutput(new ByteArrayOutputStreamWithIoSession(session, req.getCorrelationId()), CougarProtocol.getProtocolVersion(session));
            final CougarObjectInput in = objectIOFactory.newCougarObjectInput(new ByteArrayInputStream(req.getPayload()), CougarProtocol.getProtocolVersion(session));
            final String remoteAddress = ((InetSocketAddress) session.getRemoteAddress()).getAddress().getHostAddress();
            final SocketTransportCommandImpl command = new SocketTransportRPCCommandImpl(in, out, remoteAddress, session);

            requestsReceived.incrementAndGet();
View Full Code Here

TOP

Related Classes of com.betfair.cougar.transport.api.protocol.CougarObjectOutput

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.