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::ip::tcp::endpoint`对象,指定服务器的IP地址和端口号,然后调用acceptor的`open`方法打开对应的协议族,`bind`方法绑定到指定端口。 2. **监听客户端连接** 调用`acceptor`...
QuickFix 是一个开源的金融信息交换(FIX)协议实现库,专为交易系统设计,用于高效、可靠地传输证券和衍生品交易相关的数据。FIX 协议是一种国际标准,广泛应用于金融机构之间,包括股票、债券、期货、期权等各种...
ip::tcp::acceptor acceptor(io_service, ip::tcp::endpoint(ip::tcp::v4(), PORT)); while (true) { // 接受客户端连接 ip::tcp::socket socket(io_service); acceptor.accept(socket); // 打印客户端信息...
1. 接受器(Acceptor):Acceptor 是被动的一方,负责监听来自远程连接器的连接请求。它包含一个被动模式的传输端点工厂,可以创建新的数据传输端点,与Service Handler一起处理接收的数据。Acceptor通过调用`open`...
acceptor.async_accept(socket, [socket](const boost::system::error_code& error) { if (!error) { // 连接成功,处理新连接... } }); ``` 在处理连接时,通常会使用`streambuf`或`buffer`来读写数据。例如,...
在Boost ASIO中,这些操作可以通过`boost::asio::ip::tcp::acceptor`(服务器端)和`boost::asio::ip::tcp::socket`(客户端)类来实现。 **TCP服务端**,在"TestServer"文件中,通常会包含以下步骤: 1. 初始化IO...
方正FIX统一金融接入平台接口规范是一份详细阐述了方正证券股份有限公司如何通过FIX(Financial Information eXchange)协议实现金融交易系统接入的文档。FIX协议是一种国际标准化的通信协议,广泛应用于金融行业,...
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- Es una template para crear un proyecto de solo aceptor de quickfixj con spring boot 残障人士体育俱乐部 mvn全新安装 即插即用
2. **创建Acceptor**:Asio提供了`boost::asio::ip::tcp::acceptor`类,用于监听特定端口上的连接请求。我们需要实例化一个Acceptor,并调用`open()`方法打开一个指定的端口,然后调用`listen()`方法开始监听。 3. ...
boost::asio::ip::tcp::acceptor acceptor(io_service, boost::asio::ip::tcp::endpoint(boost::asio::ip::tcp::v4(), 12345)); ``` 2. **接收连接**:`acceptor`对象有一个`accept`方法,它可以接受一个新的连接并...
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; } ``` ...
ip::tcp::acceptor acceptor(ioserv, ip::tcp::endpoint(ip::tcp::v4(), 1000)); // 无限循环等待客户端连接 for (;;) { // 创建一个socket对象 ip::tcp::socket socket(ioserv); // 等待直到客户端连接...
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_...
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; } ``` ...
例如,ip::tcp::acceptor服务用于接受新的TCP连接,而对应的处理器则负责实际的接收操作。 7. **工作线程和事件循环**:io_service通常在一个事件循环中运行,这个循环会在有新事件时唤醒。可以使用work对象来保持...
2. **Acceptor(监听器)**:在服务器端,使用`boost::asio::ip::tcp::acceptor`来监听特定的端口,等待客户端的连接请求。当有新的连接请求时,Acceptor会启动一个异步接受操作,完成后回调指定的函数。 3. **...
import inc.pyc.bill.acceptor._, Events._, Commands._lazy val acceptor = context.actorOf(BillAcceptor.props(context.system), "BillAcceptor")向票据接收者发送命令的示例。 acceptor ! Listen命令Listen : ...
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....