Package org.zeromq

# Class ZContext

java.lang.Object
org.zeromq.ZContext

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

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.

See Also:
  - czmq version

## Constructor Summary

Constructors
Constructor
Description
`ZContext()`
Class Constructor

## Method Summary

Modifier and Type
Method
Description
`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 Details

### ZContext

public ZContext()
Class Constructor

## Method Details

### 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()

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`