// Path: src/main/java/org/fixtrading/timpani/securitydef/SecurityDefinitionService.java
// public interface SecurityDefinitionService extends AutoCloseable {
// 
//   CompletableFuture<Integer> serve(
//       SecurityDefinitionRequest securityDefinitionRequest,
//       Consumer<SecurityDefinitionImpl> consumer);
// 
// }
// 
// Path: src/main/java/org/fixtrading/timpani/securitydef/SecurityDefinitionServiceImpl.java
// public class SecurityDefinitionServiceImpl implements SecurityDefinitionService {
// 
//   private final MongoDBSecurityDefinitionStore store = new MongoDBSecurityDefinitionStore();
//   private final Logger logger;
// 
// 
//   public SecurityDefinitionServiceImpl() throws InterruptedException, ExecutionException {
//     logger = Log.getRootLogger();
//     store.open().get();
//   }
// 
//   @Override
//   public void close() throws Exception {
//     store.close();
//     logger.info("SecurityDefinitionServiceImpl closed");
//   }
// 
//   @Override
//   public CompletableFuture<Integer> serve(
//       SecurityDefinitionRequest securityDefinitionRequest, Consumer<SecurityDefinitionImpl> consumer) {
//     logger.debug("SecurityDefinitionServiceImpl serving request %s", securityDefinitionRequest);
// 
//     return store.select(securityDefinitionRequest, sd -> {
//       SecurityDefinitionImpl impl = (SecurityDefinitionImpl) sd;
//       impl.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//       impl.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//       impl.setSecurityRequestResult(SecurityRequestResult.ValidRequest);
//       consumer.accept(impl);
//     }).handle((count, error) -> {
//       if (error == null) {
//         if (count == 0) {
//           logger.debug("SecurityDefinitionServiceImpl: Zero security defintions returned" );
//           SecurityDefinitionImpl securityDefinition = new SecurityDefinitionImpl();
//           securityDefinition.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//           securityDefinition.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//           securityDefinition.setSecurityRequestResult(SecurityRequestResult.NoInstrumentsFound);
//           consumer.accept(securityDefinition);
//         }
//       } else {
//         logger.warn("SecurityDefinitionServiceImpl error %s", error.getMessage());
//         SecurityDefinitionImpl securityDefinition = new SecurityDefinitionImpl();
//         securityDefinition.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//         securityDefinition.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//         securityDefinition.setSecurityRequestResult(SecurityRequestResult.InstrumentDataTemporarilyUnavailable);
//         consumer.accept(securityDefinition);
//       }
//       return count;
//     });
//   }
// }


import java.util.concurrent.ExecutionException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.fixtrading.timpani.securitydef.SecurityDefinitionService;
import org.fixtrading.timpani.securitydef.SecurityDefinitionServiceImpl;
/**
 * Copyright 2016 FIX Protocol Ltd
 *
 * 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.
 *
 */
package org.fixtrading.timpani.websockets;



/**
 * Servlet implementation
 * <p>
 * Jetty provides the ability to wire up WebSocket endpoints to Servlet Path Specs via the use of a
 * WebSocketServlet bridge servlet. Internally, Jetty manages the HTTP Upgrade to WebSocket and
 * migration from a HTTP Connection to a WebSocket Connection.
 * 
 * @author Don Mendelson
 */
// @WebServlet(urlPatterns = "/SecurityDefinitions")
public class SecurityDefinitionServlet extends WebSocketServlet {
  private static final long serialVersionUID = 1L;

  private SecurityDefinitionService service;
  private Logger logger;

  @Override
  public void configure(WebSocketServletFactory factory) {
    logger = Log.getRootLogger();
    factory.getPolicy().setIdleTimeout(120000);
    // factory.register(SecurityDefSocket.class);
    try {
// Path: src/main/java/org/fixtrading/timpani/securitydef/SecurityDefinitionService.java
// public interface SecurityDefinitionService extends AutoCloseable {
// 
//   CompletableFuture<Integer> serve(
//       SecurityDefinitionRequest securityDefinitionRequest,
//       Consumer<SecurityDefinitionImpl> consumer);
// 
// }
// 
// Path: src/main/java/org/fixtrading/timpani/securitydef/SecurityDefinitionServiceImpl.java
// public class SecurityDefinitionServiceImpl implements SecurityDefinitionService {
// 
//   private final MongoDBSecurityDefinitionStore store = new MongoDBSecurityDefinitionStore();
//   private final Logger logger;
// 
// 
//   public SecurityDefinitionServiceImpl() throws InterruptedException, ExecutionException {
//     logger = Log.getRootLogger();
//     store.open().get();
//   }
// 
//   @Override
//   public void close() throws Exception {
//     store.close();
//     logger.info("SecurityDefinitionServiceImpl closed");
//   }
// 
//   @Override
//   public CompletableFuture<Integer> serve(
//       SecurityDefinitionRequest securityDefinitionRequest, Consumer<SecurityDefinitionImpl> consumer) {
//     logger.debug("SecurityDefinitionServiceImpl serving request %s", securityDefinitionRequest);
// 
//     return store.select(securityDefinitionRequest, sd -> {
//       SecurityDefinitionImpl impl = (SecurityDefinitionImpl) sd;
//       impl.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//       impl.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//       impl.setSecurityRequestResult(SecurityRequestResult.ValidRequest);
//       consumer.accept(impl);
//     }).handle((count, error) -> {
//       if (error == null) {
//         if (count == 0) {
//           logger.debug("SecurityDefinitionServiceImpl: Zero security defintions returned" );
//           SecurityDefinitionImpl securityDefinition = new SecurityDefinitionImpl();
//           securityDefinition.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//           securityDefinition.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//           securityDefinition.setSecurityRequestResult(SecurityRequestResult.NoInstrumentsFound);
//           consumer.accept(securityDefinition);
//         }
//       } else {
//         logger.warn("SecurityDefinitionServiceImpl error %s", error.getMessage());
//         SecurityDefinitionImpl securityDefinition = new SecurityDefinitionImpl();
//         securityDefinition.setSecurityReqID(securityDefinitionRequest.getSecurityReqID());
//         securityDefinition.setSubscriptionRequestType(securityDefinitionRequest.getSubscriptionRequestType());
//         securityDefinition.setSecurityRequestResult(SecurityRequestResult.InstrumentDataTemporarilyUnavailable);
//         consumer.accept(securityDefinition);
//       }
//       return count;
//     });
//   }
// }


// Path: src/main/java/org/fixtrading/timpani/websockets/SecurityDefinitionServlet.java
import java.util.concurrent.ExecutionException;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
import org.fixtrading.timpani.securitydef.SecurityDefinitionService;
import org.fixtrading.timpani.securitydef.SecurityDefinitionServiceImpl;

/**
 * Copyright 2016 FIX Protocol Ltd
 *
 * 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.
 *
 */
package org.fixtrading.timpani.websockets;



/**
 * Servlet implementation
 * <p>
 * Jetty provides the ability to wire up WebSocket endpoints to Servlet Path Specs via the use of a
 * WebSocketServlet bridge servlet. Internally, Jetty manages the HTTP Upgrade to WebSocket and
 * migration from a HTTP Connection to a WebSocket Connection.
 * 
 * @author Don Mendelson
 */
// @WebServlet(urlPatterns = "/SecurityDefinitions")
public class SecurityDefinitionServlet extends WebSocketServlet {
  private static final long serialVersionUID = 1L;

  private SecurityDefinitionService service;
  private Logger logger;

  @Override
  public void configure(WebSocketServletFactory factory) {
    logger = Log.getRootLogger();
    factory.getPolicy().setIdleTimeout(120000);
    // factory.register(SecurityDefSocket.class);
    try {
      service = new SecurityDefinitionServiceImpl();