/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.apache.stonehenge.stocktrader.service;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.stonehenge.stocktrader.CustomOrderBean;
import org.apache.stonehenge.stocktrader.dal.DAOException;
import org.apache.stonehenge.stocktrader.util.OrderProcessorUtility;
import org.tempuri.OrderProcessorSkeleton;
import traderorderhost.trade.IsOnline;
import traderorderhost.trade.SubmitOrder;
import traderorderhost.trade.SubmitOrderTransactedQueue;
import com.ibm.websphere.samples.trade.OrderDataBean;
public class OrderProcessorImpl extends OrderProcessorSkeleton {
private static final Log logger = LogFactory.getLog(OrderProcessorImpl.class);
// OrderProcessManager is the controller for managing order processing.
private final OrderProcessManager orderProcessManager = new OrderProcessManager();
/**
* This method implements the isOnline operation of OrderProcessorService
* which is a In-Only Web services function.
*/
public void isOnline(IsOnline isOnline) {
logger.debug("OrderProcessorImpl.isOnline(IsOnlines)");
}
/**
* This method is the implementation of SubmitOrderTransactedQueue function
* of OrderProcessorService.
*/
public void SubmitOrderTransactedQueue(
SubmitOrderTransactedQueue submitOrderTransactedQueue) {
if (logger.isDebugEnabled()) {
logger.debug("OrderProcessorImpl.SubmitOrder(SubmitOrder)");
OrderDataBean odb = submitOrderTransactedQueue.getOrder();
logger.debug("OrderID :" + odb.getOrderID() + "\nOrderType :"
+ odb.getOrderType() + "\nSymbol :" + odb.getSymbol()
+ "\nQuantity :" + odb.getQuantity() + "\nOrder Status :"
+ odb.getOrderStatus() + "\nOrder Open Date :"
+ odb.getOpenDate() + "\nCompletionDate :"
+ odb.getCompletionDate());
}
OrderDataBean order = submitOrderTransactedQueue.getOrder();
CustomOrderBean orderData = new CustomOrderBean(order);
try {
processOrder(orderData);
} catch (DAOException e) {
logger.error("", e);
}
}
public void SubmitOrder(SubmitOrder submitOrder) {
OrderDataBean order = submitOrder.getOrder();
CustomOrderBean orderData = new CustomOrderBean(order);
try {
processOrder(orderData);
} catch (DAOException e) {
logger.error("", e);
}
}
private void processOrder(CustomOrderBean queueOrder) throws DAOException {
// 2 seconds delay to ensure that MSFT-BL has committed new order
// entries to the database which will happen when it gets HTTP 202
// accepted header
OrderProcessorUtility.pauseForTwoSeconds();
orderProcessManager.processAndCompleteOrder(queueOrder);
}
}