Skip to content

Commit 42a5bc1

Browse files
authored
Merge pull request #25 from kolybelkin/master
Final version of the changes for MBO support
2 parents a7b975b + 5206006 commit 42a5bc1

File tree

278 files changed

+56256
-8555
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

278 files changed

+56256
-8555
lines changed

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
language: java
2+
jdk:
3+
- oraclejdk8

README.md

+278-142
Large diffs are not rendered by default.

build.gradle

+1-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1 @@
1-
plugins {
2-
id "java"
3-
id "maven"
4-
id "java-library-distribution"
5-
id "com.github.samueltbrown.cucumber" version "0.9"
6-
id "org.sonarqube" version "2.0.1"
7-
id "me.champeau.gradle.jmh" version "0.3.0"
8-
}
9-
group = 'com.epam.cme'
10-
version = '1.0'
11-
sourceCompatibility = 1.8
12-
targetCompatibility = 1.8
13-
14-
repositories {
15-
mavenCentral()
16-
}
17-
18-
19-
dependencies {
20-
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
21-
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
22-
runtime group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.5'
23-
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.10'
24-
runtime group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
25-
compile group: 'net.openhft', name: 'chronicle-bytes', version: '1.7.17'
26-
compile group: 'net.openhft', name: 'koloboke-api-jdk8', version: '0.6.8'
27-
runtime group: 'net.openhft', name: 'koloboke-impl-jdk8', version: '0.6.8'
28-
compile group: 'net.openhft', name: 'chronicle-core', version: '1.7.6'
29-
30-
cucumberCompile 'info.cukes:cucumber-java:1.2.4'
31-
cucumberCompile 'info.cukes:cucumber-picocontainer:1.2.4'
32-
testCompile group: 'junit', name: 'junit', version: '4.11'
33-
}
34-
35-
distributions {
36-
main {
37-
baseName = 'b2bits-jmdp3'
38-
contents {
39-
from { 'dist' }
40-
}
41-
}
42-
}
1+
defaultTasks 'clean', 'build', 'distZip', 'distTar'

build/b2bits-jmdp3-1.0.zip

-19.5 MB
Binary file not shown.

core/build.gradle

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
group 'com.epam.cme'
2+
version '2.0'
3+
4+
apply plugin: 'java'
5+
6+
sourceCompatibility = 1.8
7+
8+
repositories {
9+
mavenCentral()
10+
}
11+
12+
jar {
13+
baseName 'b2bits-jmdp3-core'
14+
}
15+
16+
dependencies {
17+
compile group: 'net.openhft', name: 'chronicle-bytes', version: '1.7.17'
18+
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.10'
19+
runtime group: 'commons-collections', name: 'commons-collections', version: '3.2.2'
20+
testCompile group: 'junit', name: 'junit', version: '4.12'
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2004-2016 EPAM Systems
3+
* This file is part of Java Market Data Handler for CME Market Data (MDP 3.0).
4+
* Java Market Data Handler for CME Market Data (MDP 3.0) is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* Java Market Data Handler for CME Market Data (MDP 3.0) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
* See the GNU General Public License for more details.
9+
* You should have received a copy of the GNU General Public License along with Java Market Data Handler for CME Market Data (MDP 3.0).
10+
* If not, see <http://www.gnu.org/licenses/>.
11+
*/
12+
13+
package com.epam.cme.mdp3;
14+
15+
public interface MdConstants {
16+
byte TOP_OF_THE_BOOK_LEVEL = 1;
17+
18+
int LAST_MSG_SEQ_NUM_PROCESSED = 369;
19+
int SECURITY_ID = 48;
20+
int SEC_DESC_TAG = 55;
21+
int RPT_SEQ_NUM = 83;
22+
int NO_MD_ENTRIES = 268;
23+
int INCR_RFRSH_MD_ENTRY_TYPE = 269;
24+
int INCR_RFRSH_MD_ACTION = 279;
25+
int INCR_RFRSH_MD_PRICE_LEVEL = 1023;
26+
int INCR_RFRSH_MD_ENTRY_PX = 270;
27+
int INCR_RFRSH_MD_ENTRY_SIZE = 271;
28+
int INCR_RFRSH_MD_ORDER_NUM = 346;
29+
int NO_ORDER_ID_ENTRIES = 37705;
30+
int NO_CHUNKS = 37709;
31+
int CURRENT_CHUNK = 37710;
32+
int TOT_NUM_REPORTS = 911;
33+
int REFERENCE_ID = 9633;
34+
}

src/main/java/com/epam/cme/mdp3/MdpGroup.java renamed to core/src/main/java/com/epam/cme/mdp3/MdpGroup.java

+8
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public interface MdpGroup extends FieldSet {
4949
*/
5050
void getEntry(MdpGroupEntry groupEntry);
5151

52+
/**
53+
* Copies data of defined MDP Group entry to the given instance.
54+
*
55+
* @param entryNum number of entry
56+
* @param groupEntry MDP Group Entry
57+
*/
58+
void getEntry(int entryNum, MdpGroupEntry groupEntry);
59+
5260
/**
5361
* Creates copy of the current Mdp Group
5462
*

src/main/java/com/epam/cme/mdp3/MdpPacket.java renamed to core/src/main/java/com/epam/cme/mdp3/MdpPacket.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ public static MdpPacket instance() {
5757
* @return new instance of MDP Packet
5858
*/
5959
public static MdpPacket allocate() {
60+
return allocate(MDP_PACKET_MAX_SIZE);
61+
}
62+
63+
public static MdpPacket allocate(int size) {
6064
final MdpPacket packet = instance();
61-
final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(SbeConstants.MDP_PACKET_MAX_SIZE).order(ByteOrder.LITTLE_ENDIAN);
65+
final ByteBuffer byteBuffer = ByteBuffer.allocateDirect(size).order(ByteOrder.LITTLE_ENDIAN);
6266
packet.wrapFromBuffer(byteBuffer);
6367
return packet;
6468
}
@@ -69,7 +73,7 @@ public static MdpPacket allocate() {
6973
* @return copy instance of MDP Packet
7074
*/
7175
public MdpPacket copy() {
72-
final MdpPacket copyInstance = allocate();
76+
final MdpPacket copyInstance = allocate(buffer().length());
7377
copyInstance.buffer().copyFrom(this.buffer());
7478
return copyInstance;
7579
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright 2004-2016 EPAM Systems
3+
* This file is part of Java Market Data Handler for CME Market Data (MDP 3.0).
4+
* Java Market Data Handler for CME Market Data (MDP 3.0) is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* Java Market Data Handler for CME Market Data (MDP 3.0) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
* See the GNU General Public License for more details.
9+
* You should have received a copy of the GNU General Public License along with Java Market Data Handler for CME Market Data (MDP 3.0).
10+
* If not, see <http://www.gnu.org/licenses/>.
11+
*/
12+
13+
package com.epam.cme.mdp3.core.channel;
14+
15+
16+
import com.epam.cme.mdp3.*;
17+
18+
public interface CoreChannelListener {
19+
/**
20+
* Called when a Channel Feed is started.
21+
*
22+
* @param channelId ID of MDP Channel
23+
* @param feedType Type of MDP Feed (e.g. snapshot or incremental)
24+
* @param feed Feed (e.g. A or B)
25+
*/
26+
void onFeedStarted(final String channelId, final FeedType feedType, final Feed feed);
27+
28+
/**
29+
* Called when a Channel Feed is stopped.
30+
*
31+
* @param channelId ID of MDP Channel
32+
* @param feedType type of MDP Feed (e.g. snapshot or incremental)
33+
* @param feed feed (e.g. A or B)
34+
*/
35+
void onFeedStopped(final String channelId, final FeedType feedType, final Feed feed);
36+
37+
/**
38+
* Called when a Channel Feed received new MDP Packet.
39+
*
40+
* @param channelId ID of MDP Channel
41+
* @param feedType Type of MDP Feed (e.g. snapshot or incremental)
42+
* @param feed Feed (e.g. A or B)
43+
* @param mdpPacket MDP Packet which is just received and will be handled after this callback
44+
*/
45+
void onPacket(final String channelId, final FeedType feedType, final Feed feed, final MdpPacket mdpPacket);
46+
47+
/**
48+
* Called when a Channel has to start its reset.
49+
*
50+
* @param channelId ID of MDP Channel
51+
* @param resetMessage MDP Reset Message
52+
*/
53+
void onBeforeChannelReset(final String channelId, final MdpMessage resetMessage);
54+
55+
/**
56+
* Called when a Channel just finished its reset.
57+
*
58+
* @param channelId ID of MDP Channel
59+
* @param resetMessage MDP Reset Message
60+
*/
61+
void onFinishedChannelReset(final String channelId, final MdpMessage resetMessage);
62+
63+
/**
64+
* Called when a Channel state is changed.
65+
*
66+
* @param channelId ID of MDP Channel
67+
* @param prevState Previous state
68+
* @param newState New state
69+
*/
70+
void onChannelStateChanged(final String channelId, final ChannelState prevState, final ChannelState newState);
71+
72+
/**
73+
* Called when MDP Security Definition Message is received and processed.
74+
*
75+
* @param channelId ID of MDP Channel
76+
* @param secDefMessage MDP Security Definition Message
77+
* @return Required Subscription flags
78+
* @see MdEventFlags
79+
*/
80+
int onSecurityDefinition(final String channelId, final MdpMessage secDefMessage);
81+
82+
/**
83+
* Called when MDP RFQ Message is received and processed.
84+
*
85+
* @param channelId ID of MDP Channel
86+
* @param rfqMessage MDP TFQ Message
87+
*/
88+
void onRequestForQuote(final String channelId, final MdpMessage rfqMessage);
89+
90+
/**
91+
* Called when MDP Security Status Message is received and processed.
92+
*
93+
* @param channelId ID of MDP Channel
94+
* @param securityId Security ID
95+
* @param secStatusMessage MDP Security Status Message
96+
*/
97+
void onSecurityStatus(final String channelId, final int securityId, final MdpMessage secStatusMessage);
98+
}

src/main/java/com/epam/cme/mdp3/core/channel/MdpFeedContext.java renamed to core/src/main/java/com/epam/cme/mdp3/core/channel/MdpFeedContext.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
package com.epam.cme.mdp3.core.channel;
1414

1515
import com.epam.cme.mdp3.*;
16+
import com.epam.cme.mdp3.core.cfg.ConnectionCfg;
1617
import com.epam.cme.mdp3.sbe.message.SbeDouble;
1718
import com.epam.cme.mdp3.sbe.message.SbeGroup;
1819
import com.epam.cme.mdp3.sbe.message.SbeGroupEntry;
@@ -32,9 +33,9 @@ public MdpFeedContext(final Feed feed, final FeedType feedType) {
3233
this.feedType = feedType;
3334
}
3435

35-
public MdpFeedContext(final MdpFeedWorker feedConnection) {
36-
this.feed = feedConnection.getCfg().getFeed();
37-
this.feedType = feedConnection.getCfg().getFeedType();
36+
public MdpFeedContext(final ConnectionCfg cfg) {
37+
this.feed = cfg.getFeed();
38+
this.feedType = cfg.getFeedType();
3839
}
3940

4041
public MdpPacket getMdpPacket() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Copyright 2004-2016 EPAM Systems
3+
* This file is part of Java Market Data Handler for CME Market Data (MDP 3.0).
4+
* Java Market Data Handler for CME Market Data (MDP 3.0) is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* Java Market Data Handler for CME Market Data (MDP 3.0) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
* See the GNU General Public License for more details.
9+
* You should have received a copy of the GNU General Public License along with Java Market Data Handler for CME Market Data (MDP 3.0).
10+
* If not, see <http://www.gnu.org/licenses/>.
11+
*/
12+
13+
package com.epam.cme.mdp3.core.channel;
14+
15+
public enum MdpFeedRtmState {
16+
ACTIVE, PENDING_SHUTDOWN, SHUTDOWN, STOPPED
17+
}

src/main/java/com/epam/cme/mdp3/core/channel/MdpFeedWorker.java renamed to core/src/main/java/com/epam/cme/mdp3/core/channel/MdpFeedWorker.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public MdpFeedWorker(final ConnectionCfg cfg, final String networkInterface, fin
6666

6767
void init() throws MdpFeedException {
6868
try {
69-
this.feedContext = new MdpFeedContext(this);
69+
this.feedContext = new MdpFeedContext(getCfg());
7070
this.ni = this.networkInterface != null ? NetworkInterface.getByName(this.networkInterface) : NetworkInterface.getByInetAddress(InetAddress.getLocalHost());
7171
} catch (IOException e) {
7272
logger.error("Failed open DatagramChannel", e);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2004-2016 EPAM Systems
3+
* This file is part of Java Market Data Handler for CME Market Data (MDP 3.0).
4+
* Java Market Data Handler for CME Market Data (MDP 3.0) is free software: you can redistribute it and/or modify it under the terms of the
5+
* GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
6+
* Java Market Data Handler for CME Market Data (MDP 3.0) is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7+
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
* See the GNU General Public License for more details.
9+
* You should have received a copy of the GNU General Public License along with Java Market Data Handler for CME Market Data (MDP 3.0).
10+
* If not, see <http://www.gnu.org/licenses/>.
11+
*/
12+
13+
package com.epam.cme.mdp3.core.channel.tcp;
14+
15+
import com.epam.cme.mdp3.core.cfg.ConnectionCfg;
16+
import com.epam.cme.mdp3.core.channel.MdpFeedContext;
17+
import org.slf4j.Logger;
18+
import org.slf4j.LoggerFactory;
19+
20+
import java.io.EOFException;
21+
import java.io.IOException;
22+
import java.net.InetSocketAddress;
23+
import java.nio.ByteBuffer;
24+
import java.nio.channels.SocketChannel;
25+
import java.util.List;
26+
27+
public class MdpTCPChannel implements TCPChannel {
28+
private static final Logger logger = LoggerFactory.getLogger(MdpTCPChannel.class);
29+
private final ConnectionCfg cfg;
30+
private volatile SocketChannel socketChannel;
31+
private MdpFeedContext feedContext;
32+
33+
public MdpTCPChannel(final ConnectionCfg cfg) {
34+
this.cfg = cfg;
35+
this.feedContext = new MdpFeedContext(cfg);
36+
}
37+
38+
@Override
39+
public boolean connect() {
40+
List<String> hostIPs = cfg.getHostIPs();
41+
for (String hostIP : hostIPs) {
42+
try {
43+
final InetSocketAddress inetSocketAddress = new InetSocketAddress(hostIP, cfg.getPort());
44+
socketChannel = SocketChannel.open(inetSocketAddress);
45+
logger.debug("Connected to {}:{}", hostIP, cfg.getPort());
46+
return true;
47+
} catch (Exception e) {
48+
logger.error("Failed to connect to {}:{}. Exception: {}", hostIP, cfg.getPort(), e.getMessage(), e);
49+
}
50+
}
51+
return false;
52+
}
53+
54+
@Override
55+
public void disconnect() {
56+
try {
57+
socketChannel.close();
58+
} catch (IOException e) {
59+
logger.error(e.getMessage(), e);
60+
}
61+
}
62+
63+
@Override
64+
public void send(ByteBuffer bb) throws IOException {
65+
socketChannel.write(bb);
66+
}
67+
68+
@Override
69+
public int receive(ByteBuffer bb) throws IOException {
70+
int readBytes = socketChannel.read(bb);
71+
if(readBytes < 0) {
72+
throw new EOFException("Length of last received bytes is less than zero '" + readBytes + "'");
73+
} else {
74+
return readBytes;
75+
}
76+
}
77+
78+
@Override
79+
public MdpFeedContext getFeedContext() {
80+
return feedContext;
81+
}
82+
}

0 commit comments

Comments
 (0)