org.zeromq
Class ZContext

java.lang.Object
  extended by org.zeromq.ZContext
All Implemented Interfaces:
Closeable

public class ZContext
extends Object
implements Closeable

ZContext provides a high-level ZeroMQ context management class The ZContext class wraps java org.zeromq.Context objects, which in turn wrap native 0MQ contexts. It manages open sockets in the context and automatically closes these before terminating the context. It provides a simple way to set the linger timeout on sockets, and configure contexts for number of I/O threads. Sets-up signal (interrupt) handling for the process.

Author:
rsmith (at) rsbatechnology (dot) co (dot) uk
See Also:
http://github.com/zeromq/czmq/blob/master/src/zctx.c

Constructor Summary
ZContext()
          Class Constructor
 
Method Summary
 void close()
           
 ZMQ.Socket createSocket(int type)
          Creates a new managed socket within this ZContext instance.
 void destroy()
          Destructor.
 void destroySocket(ZMQ.Socket s)
          Destroys managed socket within this context and remove from sockets list
 ZMQ.Context getContext()
           
 int getIoThreads()
           
 int getLinger()
           
 List<ZMQ.Socket> getSockets()
           
 boolean isMain()
           
 void setContext(ZMQ.Context ctx)
           
 void setIoThreads(int ioThreads)
           
 void setLinger(int linger)
           
 void setMain(boolean main)
           
static ZContext shadow(ZContext ctx)
          Creates new shadow context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ZContext

public ZContext()
Class Constructor

Method Detail

destroy

public void destroy()
Destructor. Call this to gracefully terminate context and close any managed 0MQ sockets


createSocket

public ZMQ.Socket createSocket(int type)
Creates a new managed socket within this ZContext instance. Use this to get automatic management of the socket at shutdown

Parameters:
type - socket type (see ZMQ static class members)
Returns:
Newly created Socket object

destroySocket

public void destroySocket(ZMQ.Socket s)
Destroys managed socket within this context and remove from sockets list

Parameters:
s - org.zeromq.Socket object to destroy

shadow

public static ZContext shadow(ZContext ctx)
Creates new shadow context. Shares same underlying org.zeromq.Context instance but has own list of managed sockets, io thread count etc.

Parameters:
ctx - Original ZContext to create shadow of
Returns:
New ZContext

getIoThreads

public int getIoThreads()
Returns:
the ioThreads

setIoThreads

public void setIoThreads(int ioThreads)
Parameters:
ioThreads - the ioThreads to set

getLinger

public int getLinger()
Returns:
the linger

setLinger

public void setLinger(int linger)
Parameters:
linger - the linger to set

isMain

public boolean isMain()
Returns:
the main

setMain

public void setMain(boolean main)
Parameters:
main - the main to set

getContext

public ZMQ.Context getContext()
Returns:
the context

setContext

public void setContext(ZMQ.Context ctx)
Parameters:
ctx - sets the underlying org.zeromq.Context associated with this ZContext wrapper object

getSockets

public List<ZMQ.Socket> getSockets()
Returns:
the sockets

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2013. All Rights Reserved.