Package com.betfair.baseline.v1

Source Code of com.betfair.baseline.v1.BaselineSyncServiceExecutableResolver

/*
* 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.baseline.v1;

import com.betfair.baseline.v1.co.*;
import com.betfair.baseline.v1.to.*;
import com.betfair.baseline.v1.enumerations.*;
import com.betfair.baseline.v1.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  BaselineService.
*/
@SuppressWarnings("all")
public class BaselineSyncServiceExecutableResolver implements ExecutableResolver {
  private Map<OperationKey, Executable> executableMap = new HashMap<OperationKey, Executable>();
  private BaselineService service;

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

                ServiceExceptionHandlingObserver exceptionHandlingObserver = new ServiceExceptionHandlingObserver(observer);

                try {
                    SimpleResponse result = service.testSimpleGet((RequestContext)ctx, (String)args[0], timeConstraints);
                    observer.onResult(new ExecutionResult(result));
                } catch (CougarException ce) {
                    exceptionHandlingObserver.onResult(new ExecutionResult(ce));
                } catch (SimpleException ex) {
                    exceptionHandlingObserver.onResult(new ExecutionResult((CougarApplicationException)ex));
                };
            }
        });

  }

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

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

}
TOP

Related Classes of com.betfair.baseline.v1.BaselineSyncServiceExecutableResolver

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.