`
seafront12
  • 浏览: 4639 次
  • 性别: Icon_minigender_1
  • 来自: 珠海
文章分类
社区版块
存档分类
最新评论

FIX with JDBC Storage: Acceptor Code quickfixj

FIX 
阅读更多
import org.quickfixj.jmx.JmxExporter;
import quickfix.ConfigError;
import quickfix.DefaultMessageFactory;
import quickfix.DoNotSend;
import quickfix.FieldNotFound;
import quickfix.IncorrectDataFormat;
import quickfix.IncorrectTagValue;
import quickfix.JdbcStoreFactory;
import quickfix.LogFactory;
import quickfix.Message;
import quickfix.MessageFactory;
import quickfix.MessageStoreFactory;
import quickfix.RejectLogon;
import quickfix.SLF4JLogFactory;
import quickfix.Session;
import quickfix.SessionID;
import quickfix.SessionNotFound;
import quickfix.SessionSettings;
import quickfix.SocketAcceptor;
import quickfix.UnsupportedMessageType;

import javax.management.JMException;
import javax.management.ObjectName;
import java.util.concurrent.CountDownLatch;

import static com.google.common.base.Throwables.propagate;
import static com.hsbc.efx.fog.io.fix.FixUtils.loadSessionSettings;

public class SingleSessionFixAcceptorApplication implements FixAcceptorApplication {
    private final SocketAcceptor acceptor;
    private final FixMsgHandler handler;
    private final ApplicationEvents applicationEvents;
    private ObjectName acceptorObjectName;
    private final JmxExporter exporter;
    private final FixConnectionListener fixConnectionListener;
    private SessionID sessionId;
    private CountDownLatch connectionEstablished;
    private boolean latchUsed = true;

    @Inject
    public SingleSessionFixAcceptorApplication(
            Config config, FixMsgHandler handler,
            ApplicationEvents applicationEvents, FixConnectionListener fixConnectionListener) {
        this.handler = handler;
        this.applicationEvents = applicationEvents;
        this.fixConnectionListener = fixConnectionListener;
        SessionSettings settings = loadSessionSettings(config.fixSettingsFile());
//        MessageStoreFactory storeFactory = new MemoryStoreFactory();
        MessageStoreFactory storeFactory = new JdbcStoreFactory(settings);
        MessageFactory messageFactory = new DefaultMessageFactory();
        LogFactory logFactory = new SLF4JLogFactory(settings);
        connectionEstablished = new CountDownLatch(1);
        try {
            this.exporter = new JmxExporter();
            acceptor = new SocketAcceptor(
                    this,
                    storeFactory,
                    settings,
                    logFactory,
                    messageFactory);
        } catch (JMException | ConfigError e) {
            throw propagate(e);
        }
    }

    public void start() {
        applicationEvents.startingFixServer();
        try {
            acceptor.start();
//            acceptorObjectName = exporter.register(acceptor);
            applicationEvents.fixServerStarted();
            if (latchUsed) {
                connectionEstablished.await();
            }
        } catch (ConfigError | InterruptedException exception) {
            throw propagate(exception);
        }

    }

    public void stop() {
        applicationEvents.stoppingFixServer();
        acceptor.stop();

        // Unregister jmx
        try {
            if (acceptorObjectName != null) {
                exporter.getMBeanServer().unregisterMBean(acceptorObjectName);
            }
            applicationEvents.fixServerStopped();
        } catch (Exception e) {
            applicationEvents.cannotUnregisterMBean("FIX server " + acceptorObjectName, e);
        }
    }

    public void send(Message message) {
        try {
            Session.sendToTarget(message, sessionId);
        } catch (SessionNotFound sessionNotFound) {
            propagate(sessionNotFound);
        }
    }

    public void onCreate(SessionID sessionID) {
    }

    public void onLogon(SessionID sessionID) {
        applicationEvents.fixClientLoggedIn(sessionID.toString());
        this.sessionId = sessionID;
        if (latchUsed) {
            connectionEstablished.countDown();
        }
        fixConnectionListener.onConnect();
    }

    public void onLogout(SessionID sessionID) {
        applicationEvents.fixClientDisconnected(sessionID.toString());
        this.sessionId = null;
        fixConnectionListener.onDisconnect();
    }

    public void fromApp(Message message, SessionID sessionID)
            throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, UnsupportedMessageType {
        handler.handleFixMessage(message);
    }

    public void toAdmin(Message message, SessionID sessionID) {
    }

    public void fromAdmin(Message message, SessionID sessionID)
            throws FieldNotFound, IncorrectDataFormat, IncorrectTagValue, RejectLogon {
    }

    public void toApp(Message message, SessionID sessionID) throws DoNotSend {
    }

    public boolean isUp() {
        return sessionId != null;
    }

    public void enableLatch(boolean enabled) {
        latchUsed = enabled;
    }
}
分享到:
评论

相关推荐

    boost asio tcp服务器的实现

    首先,我们需要创建一个`boost::asio::ip::tcp::endpoint`对象,指定服务器的IP地址和端口号,然后调用acceptor的`open`方法打开对应的协议族,`bind`方法绑定到指定端口。 2. **监听客户端连接** 调用`acceptor`...

    QuickFix 实现代码例子

    QuickFix 是一个开源的金融信息交换(FIX)协议实现库,专为交易系统设计,用于高效、可靠地传输证券和衍生品交易相关的数据。FIX 协议是一种国际标准,广泛应用于金融机构之间,包括股票、债券、期货、期权等各种...

    C++ boost::asio编程 同步TCP详解及实例代码

    ip::tcp::acceptor acceptor(io_service, ip::tcp::endpoint(ip::tcp::v4(), PORT)); while (true) { // 接受客户端连接 ip::tcp::socket socket(io_service); acceptor.accept(socket); // 打印客户端信息...

    C语言实现网络编程应用 ACE架构详解

    1. 接受器(Acceptor):Acceptor 是被动的一方,负责监听来自远程连接器的连接请求。它包含一个被动模式的传输端点工厂,可以创建新的数据传输端点,与Service Handler一起处理接收的数据。Acceptor通过调用`open`...

    C++ Boost Asio 网络库 讲解示例代码

    acceptor.async_accept(socket, [socket](const boost::system::error_code& error) { if (!error) { // 连接成功,处理新连接... } }); ``` 在处理连接时,通常会使用`streambuf`或`buffer`来读写数据。例如,...

    Boost Asio Demo.zip

    在Boost ASIO中,这些操作可以通过`boost::asio::ip::tcp::acceptor`(服务器端)和`boost::asio::ip::tcp::socket`(客户端)类来实现。 **TCP服务端**,在"TestServer"文件中,通常会包含以下步骤: 1. 初始化IO...

    方正FIX统一金融接入平台接口规范

    方正FIX统一金融接入平台接口规范是一份详细阐述了方正证券股份有限公司如何通过FIX(Financial Information eXchange)协议实现金融交易系统接入的文档。FIX协议是一种国际标准化的通信协议,广泛应用于金融行业,...

    boost-asio-cpp-network-programming.zip_BOOST教程_Boost_boost asio

    void handle_request(const boost::system::error_code& error, std::size_t bytes_transferred) { if (!error) { // 处理请求... } } int main() { boost::asio::io_context io_context; boost::asio::ip::...

    spring-quickfixj-acceptor-template:弹簧模板,快速启动,单独启动,快速启动

    spring-quickfixj-acceptor-template- Es una template para crear un proyecto de solo aceptor de quickfixj con spring boot 残障人士体育俱乐部 mvn全新安装 即插即用

    利用Asio网络库建立自己的Socket服务器

    2. **创建Acceptor**:Asio提供了`boost::asio::ip::tcp::acceptor`类,用于监听特定端口上的连接请求。我们需要实例化一个Acceptor,并调用`open()`方法打开一个指定的端口,然后调用`listen()`方法开始监听。 3. ...

    boost asio 服务器和客户端 TCP

    boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345)); ``` 2. **接收连接**:`acceptor`对象有一个`accept`方法,它可以接受一个新的连接并...

    boost::asio测试程序(vs2005)

    boost::system::error_code ignored_error; boost::asio::write(socket, boost::asio::buffer(message), ignored_error); } } catch (std::exception& e) { std::cerr () << std::endl; } return 0; } ``` ...

    Boost_asio权威傻瓜教程

    ip::tcp::acceptor acceptor(ioserv, ip::tcp::endpoint(ip::tcp::v4(), 1000)); // 无限循环等待客户端连接 for (;;) { // 创建一个socket对象 ip::tcp::socket socket(ioserv); // 等待直到客户端连接...

    boost asio傻瓜教程

    ip::tcp::acceptor acceptor(iosev, ip::tcp::endpoint(ip::tcp::v4(), 1000)); for (;;) { ip::tcp::socket socket(iosev); acceptor.accept(socket); std::cout ().address() << std::endl; socket.write_...

    Ubuntu安装boost加测试程序

    boost::system::error_code ignored_error; boost::asio::write(socket, boost::asio::buffer(message), ignored_error); } } catch (std::exception& e) { std::cerr () << std::endl; } return 0; } ``` ...

    Boost ASIO C++ 网络编程-带实例

    例如,ip::tcp::acceptor服务用于接受新的TCP连接,而对应的处理器则负责实际的接收操作。 7. **工作线程和事件循环**:io_service通常在一个事件循环中运行,这个循环会在有新事件时唤醒。可以使用work对象来保持...

    基于BoostAsio的异步通信Demo

    2. **Acceptor(监听器)**:在服务器端,使用`boost::asio::ip::tcp::acceptor`来监听特定的端口,等待客户端的连接请求。当有新的连接请求时,Acceptor会启动一个异步接受操作,完成后回调指定的函数。 3. **...

    bill-acceptor:Akka 演员通过 rs-232 串行连接与票据接受者进行通信

    import inc.pyc.bill.acceptor._, Events._, Commands._lazy val acceptor = context.actorOf(BillAcceptor.props(context.system), "BillAcceptor")向票据接收者发送命令的示例。 acceptor ! Listen命令Listen : ...

    Ubuntu 上采用 Boost asio 异步 TCP 通讯boostasiotcp-master.zip

    boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345)); for (;;) { boost::asio::ip::tcp::socket socket(io_service); acceptor....

Global site tag (gtag.js) - Google Analytics