Package com.betfair.cougar.health.service.v3

Source Code of com.betfair.cougar.health.service.v3.HealthSyncServiceExecutableResolver

/*
* Copyright 2013, The Sporting Exchange Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2013, The Sporting Exchange Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* Copyright 2013, The Sporting Exchange Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// Generated from syncServiceExecutableResolver.ftl
package com.betfair.cougar.health.service.v3;

import com.betfair.cougar.health.service.v3.co.*;
import com.betfair.cougar.health.service.v3.to.*;
import com.betfair.cougar.health.service.v3.enumerations.*;
import com.betfair.cougar.health.service.v3.exception.*;
import com.betfair.cougar.core.api.ev.ConnectedResponse;
import com.betfair.cougar.api.ExecutionContext;
import com.betfair.cougar.api.RequestContext;
import com.betfair.cougar.api.fault.CougarApplicationException;
import com.betfair.cougar.core.api.exception.CougarException;
import com.betfair.cougar.core.api.exception.CougarClientException;
import com.betfair.cougar.core.api.exception.CougarServiceException;
import com.betfair.cougar.core.api.exception.ServerFaultCode;
import com.betfair.cougar.core.api.ev.Executable;
import com.betfair.cougar.core.api.ev.ExecutableResolver;
import com.betfair.cougar.core.api.ev.ExecutionObserver;
import com.betfair.cougar.core.api.ev.ExecutionResult;
import com.betfair.cougar.core.api.ev.ExecutionVenue;
import com.betfair.cougar.core.api.ev.OperationKey;
import com.betfair.cougar.core.api.ev.TimeConstraints;
import com.betfair.cougar.core.impl.ev.ServiceExceptionHandlingObserver;

import java.util.*;

/**
* Resolves Executables for all operations in the synchronous  HealthService.
*/
@SuppressWarnings("all")
public class HealthSyncServiceExecutableResolver implements ExecutableResolver {
  private Map<OperationKey, Executable> executableMap = new HashMap<OperationKey, Executable>();
  private HealthService service;

  public HealthSyncServiceExecutableResolver() {
      executableMap.put(HealthServiceDefinition.isHealthyKey,
            new Executable() {
                @Override
                public void execute(ExecutionContext ctx, OperationKey key,
                        Object[] args, ExecutionObserver observer,
                        ExecutionVenue executionVenue, TimeConstraints timeConstraints) {

                ServiceExceptionHandlingObserver exceptionHandlingObserver = new ServiceExceptionHandlingObserver(observer);

                try {
                    HealthSummaryResponse result = service.isHealthy((RequestContext)ctx, timeConstraints);
                    observer.onResult(new ExecutionResult(result));
                } catch (CougarException ce) {
                    exceptionHandlingObserver.onResult(new ExecutionResult(ce));
                } catch (HealthException ex) {
                    exceptionHandlingObserver.onResult(new ExecutionResult((CougarApplicationException)ex));
                };
            }
        });

      executableMap.put(HealthServiceDefinition.getDetailedHealthStatusKey,
            new Executable() {
                @Override
                public void execute(ExecutionContext ctx, OperationKey key,
                        Object[] args, ExecutionObserver observer,
                        ExecutionVenue executionVenue, TimeConstraints timeConstraints) {

                ServiceExceptionHandlingObserver exceptionHandlingObserver = new ServiceExceptionHandlingObserver(observer);

                try {
                    HealthDetailResponse result = service.getDetailedHealthStatus((RequestContext)ctx, timeConstraints);
                    observer.onResult(new ExecutionResult(result));
                } catch (CougarException ce) {
                    exceptionHandlingObserver.onResult(new ExecutionResult(ce));
                } catch (HealthException ex) {
                    exceptionHandlingObserver.onResult(new ExecutionResult((CougarApplicationException)ex));
                };
            }
        });

  }

  public void setService(HealthService service) {
      this.service = service;
  }

  @Override
  public Executable resolveExecutable(OperationKey operationKey, ExecutionVenue ev) {
    return executableMap.get(operationKey);
  }
 

}
TOP

Related Classes of com.betfair.cougar.health.service.v3.HealthSyncServiceExecutableResolver

TOP
Copyright © 2018 www.massapi.com. 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.