Package com.betfair.cougar.core.api.exception

Examples of com.betfair.cougar.core.api.exception.CougarClientException


                   new Object[] { },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation isHealthy timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (HealthSummaryResponse) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("HealthException")) {
                        throw new HealthException(
                                                cex.getResponseCode(),
                                                   HealthExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here


                   new Object[] { },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation getDetailedHealthStatus timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (HealthDetailResponse) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("HealthException")) {
                        throw new HealthException(
                                                cex.getResponseCode(),
                                                   HealthExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

        final NewHeapSubscription newHeapSubscription;
        try {
            newHeapSubscription = (NewHeapSubscription) in.getResult();
        } catch (Exception e) {
            logger.log(Level.WARNING, "Error unpacking subscription result", e);
            observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError, "Error unpacking subscription result", e)));
            return;
        }
        nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Received a subscription response for heapId %s with subscriptionId %s", newHeapSubscription.getHeapId(), newHeapSubscription.getSubscriptionId());

        final String sessionId = NioUtils.getSessionId(currentSession);
        ConnectedHeaps heaps;
        heapSubMutationLock.lock();
        try {
            heaps = heapsByServer.get(sessionId);
            if (heaps == null) {
                heaps = new ConnectedHeaps();
                heapsByServer.put(sessionId, heaps);
            }
        } finally {
            heapSubMutationLock.unlock();
        }

        // new heap
        boolean newHeap = false;
        if (newHeapSubscription.getUri() != null) {
            nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Received a new heap definition, heapId = %s, heapUrl = %s", newHeapSubscription.getHeapId(), newHeapSubscription.getUri());
            newHeap = heaps.addHeap(newHeapSubscription.getHeapId(), newHeapSubscription.getUri());
            if (!newHeap) {
                nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Received a new heap definition, heapId = %s, even though we know about the heap already!", newHeapSubscription.getHeapId());
            }
        }
        final boolean preExistingHeap = !newHeap;

        // find heap uri
        final HeapState heapState = heaps.getHeapState(newHeapSubscription.getHeapId());
        if (heapState == null) {
            nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Couldn't find heap definition, heapId = %s", newHeapSubscription.getHeapId());
            logger.log(Level.WARNING, "Can't find the heap for this subscription result. Heap id = " + newHeapSubscription.getHeapId());
            observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError, "Can't find the heap for this subscription result. Heap id = " + newHeapSubscription.getHeapId())));
        } else {
            if (preExistingHeap && heapState.haveSeenInitialUpdate()) {
                Subscription sub = heapState.addSubscription(this, currentSession, newHeapSubscription.getHeapId(), newHeapSubscription.getSubscriptionId());
                if (sub != null) {
                    observer.onResult(new ExecutionResult(new ConnectedResponseImpl(heapState.getHeap(), sub)));
                } else {
                    // null sub means we already had a subscription with that id, something's not in a good state in the server, so kill this connection as we don't know what's going on
                    nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Duplicate subscription returned by the server, id = %s - closing session", newHeapSubscription.getSubscriptionId());
                    logger.log(Level.WARNING, "Duplicate subscription returned by the server, id = " + newHeapSubscription.getSubscriptionId() + " - closing session");
                    observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError, "Duplicate subscription returned by the server, id = " + newHeapSubscription.getSubscriptionId())));
                    currentSession.close();
                }
            } else {
                // split this off into it's own thread since the mina docs lie and we only have one ioprocessor thread and if we don't fork we'd block forever
                final ConnectedHeaps finalHeaps = heaps;
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        boolean resultSent = false;
                        // now we've got the heap
                        CountDownLatch initialPopulationLatch = finalHeaps.getInitialPopulationLatch(newHeapSubscription.getHeapId());
                        try {
                            boolean populated = false;
                            if (initialPopulationLatch != null) {
                                nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Waiting for initial heap population, heapUrl = %s", newHeapSubscription.getUri());
                                populated = initialPopulationLatch.await(maxInitialPopulationWait, TimeUnit.MILLISECONDS);
                                finalHeaps.removeInitialPopulationLatch(newHeapSubscription.getHeapId());
                            } else {
                                nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Initial heap population, heapUrl = %s", newHeapSubscription.getUri());

                            }
                            nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Returning heap to client, heapUrl = %s", newHeapSubscription.getUri());
                            if (populated) {
                                observer.onResult(new ExecutionResult(new ConnectedResponseImpl(heapState.getHeap(), heapState.addSubscription(ClientConnectedObjectManager.this, currentSession, newHeapSubscription.getHeapId(), newHeapSubscription.getSubscriptionId()))));
                                resultSent = true;
                            }
                        } catch (InterruptedException e) {
                            // we got interrupted waiting for the response, oh well..
                        } catch (RuntimeException e) {
                            logger.log(Level.WARNING, "Error processing initial heap population, treating as a failure", e);
                        } finally {
                            if (!resultSent) {
                                nioLogger.log(NioLogger.LoggingLevel.TRANSPORT, currentSession, "Didn't get initial population message for heap, heapUrl = %s", newHeapSubscription.getUri());
                                // we don't worry about the case where it was a preExisting heap since the thread where it wasn't received will deal with it
                                if (!preExistingHeap) {
                                    terminateSubscriptions(currentSession, newHeapSubscription.getHeapId(), Subscription.CloseReason.INTERNAL_ERROR);
                                }
                                logger.log(Level.WARNING, "Didn't get initial population message for heap id = " + newHeapSubscription.getHeapId());
                                observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError, "Didn't get initial population message for heap id = " + newHeapSubscription.getHeapId())));
                            }
                        }
                    }
                }, "SubscriptionResponseHandler-InitialPopulation-" + initialPopulationThreadIdSource.incrementAndGet() + "-" + heapState.getHeapUri()).start();
            }
View Full Code Here

                LOG.log(Level.SEVERE, "An attempt was made to execute a method when the client was not connected!");
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.log(Level.FINE,
                            "Operation: " + def.getOperationKey() + " with parameters: " + Arrays.toString(args));
                }
                observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError,
                        "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));

                            try {
                                EnumUtils.setHardFailureForThisThread(hardFailEnumDeserialisation);
                                InvocationResponse response = marshaller.readInvocationResponse(def.getReturnType(), in);
                                // connected object calls need some additional setup prior to responding to the observer
                                if (def.getOperationKey().getType() == OperationKey.Type.ConnectedObject && response.isSuccess()) {
                                    connectedObjectManager.handleSubscriptionResponse(session, response, observer);
                                }
                                else {
                                    response.recreate(observer, def.getReturnType(), message.getPayload().length);
                                }
                            } catch (Exception e) {
                                observer.onResult(new ExecutionResult(new CougarClientException(CougarMarshallingException.unmarshallingException("binary", "Unable to deserialise response, closing session", e, true))));
                                if (session.isConnected()) {
                                    logger.log(NioLogger.LoggingLevel.SESSION, session, "Error occurred whilst trying to deserialise response, closing session");
                                    // it is possible that we never get here
                                    session.close();
                                }
                            }
                        }

                        @Override
                        public void timedOut() {
                            observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.Timeout, "Exception occurred in Client: Read timed out: "+NioUtils.getRemoteAddressUrl(session))));
                        }

                        @Override
                        public void sessionClosed() {
                            observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.RemoteCougarCommunicationFailure, "Connectivity to remote server lost!")));
                        }
                    });
                } catch (Throwable e) {
                    observer.onResult(new ExecutionResult(new CougarClientException(ServerFaultCode.FrameworkError,
                            "An exception occurred with remote method call", e)));
                }
            }
        }
    }
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation i64Operation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (I64OperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation byteOperation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (ByteOperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation floatOperation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (FloatOperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation doubleOperation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (DoubleOperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation boolOperation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (BoolOperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

                   new Object[] { headerParam , queryParam , message },
                   observer,
                   timeConstraints);

        if (!observer.await(timeConstraints)) {
            throw new CougarClientException(ServerFaultCode.Timeout, "Operation nonMandatoryParamsOperation timed out!");
        }

        final ExecutionResult er = observer.getExecutionResult();
        switch (er.getResultType()) {
            case Success:
                return (NonMandatoryParamsOperationResponseObject) er.getResult();

            case Fault:
                CougarException cex = er.getFault();

                if (cex.getServerFaultCode() == ServerFaultCode.ServiceCheckedException) {
                    List<String[]> exceptionParams = cex.getFault().getDetail().getFaultMessages();
                    String className = cex.getFault().getDetail().getDetailMessage();
                    if (className.equals("SimpleException")) {
                        throw new SimpleException(
                                                cex.getResponseCode(),
                                                   SimpleExceptionErrorCodeEnum.valueOf(exceptionParams.get(0)[1]),
                                                   (exceptionParams.get(1)[1])
                                              );
                    }

                    else {
                        throw new IllegalArgumentException("An unanticipated exception was received of class [" + className + "]");
                    }
                } else if (cex instanceof CougarFrameworkException) {
                    CougarFrameworkException cfe = (CougarFrameworkException) cex;
                    throw new CougarClientException(cfe.getServerFaultCode(), cfe.getMessage(), cfe.getCause());
                } else {
                  throw cex;
                }
            default:
                throw new IllegalArgumentException("The Server returned an illegal result type [" + er.getResultType() + "]");
View Full Code Here

TOP

Related Classes of com.betfair.cougar.core.api.exception.CougarClientException

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.