Skip to content

Commit

Permalink
Merge pull request #727 from esahekmat/394
Browse files Browse the repository at this point in the history
Create a new constructor accepting SocketType enum
  • Loading branch information
daveyarwood committed Jun 4, 2019
2 parents 6073bd7 + b806bca commit d2c09ac
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
22 changes: 22 additions & 0 deletions src/main/java/org/zeromq/ZSocket.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,32 @@ public ZSocket(final int socketType)
socketBase = ManagedContext.getInstance().createSocket(socketType);
}

/**
* Create a ZeroMQ socket
*
* @param socketType ZeroMQ Socket type
*/
public ZSocket(final SocketType socketType)
{
this(socketType.type());
}

/**
* Retrieve the socket type for the current 'socket'. The socket type is specified at socket
* creation time and cannot be modified afterwards.
*
* @return the socket's type.
*/
public SocketType getSocketType()
{
return SocketType.type(getType());
}

/**
* Retrieve the socket type for the current 'socket'. The socket type is specified at socket
* creation time and cannot be modified afterwards.
*
* @see ZSocket#getSocketType()
* @return the socket's type.
*/
public int getType()
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/zeromq/TestPushPullThreadedTcp.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ private void test(int count) throws IOException, InterruptedException
public void testIssue338() throws InterruptedException, IOException
{
try (
final ZSocket pull = new ZSocket(ZMQ.PULL);
final ZSocket push = new ZSocket(ZMQ.PUSH)) {
final ZSocket pull = new ZSocket(SocketType.PULL);
final ZSocket push = new ZSocket(SocketType.PUSH)) {
final String host = "tcp://localhost:" + Utils.findOpenPort();
pull.bind(host);
push.connect(host);
Expand Down
8 changes: 6 additions & 2 deletions src/test/java/org/zeromq/ZSocketTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ public void pushPullTest() throws IOException
int port = Utils.findOpenPort();

try (
final ZSocket pull = new ZSocket(ZMQ.PULL);
final ZSocket push = new ZSocket(ZMQ.PUSH)) {
final ZSocket pull = new ZSocket(SocketType.PULL);
final ZSocket push = new ZSocket(SocketType.PUSH)) {
pull.bind("tcp://*:" + port);
push.connect("tcp://127.0.0.1:" + port);

Expand All @@ -24,6 +24,10 @@ public void pushPullTest() throws IOException
final String actual = pull.receiveStringUtf8();

assertEquals(expected, actual);
assertEquals(SocketType.PULL, pull.getSocketType());
assertEquals(ZMQ.PULL, pull.getType());
assertEquals(SocketType.PUSH, push.getSocketType());
assertEquals(ZMQ.PUSH, push.getType());
}
}
}

0 comments on commit d2c09ac

Please sign in to comment.