Folks,

I thought my code was OK, but yesterday I put a Junit Test under ContiPerf 
annotiations to stress the zmq link and booom!!! Several problems arose.

On the client side I have: 

 try {
            req = (Socket) socketPool.borrowObject();
            
            req.send(baos.toByteArray(), NO_FLAGS); //   private static final 
int NO_FLAGS = 0;
            
            //req.setReceiveTimeOut(10000);

            data = req.recv();
            if (data == null) {
                socketPool.invalidateObject(req);
            }
        } finally {
            if (req != null) {
                socketPool.returnObject(req);
            }
        }

The object pool is as follows: 

import org.apache.commons.pool.impl.StackObjectPool;
private static StackObjectPool socketPool = null;


     socketPool = new StackObjectPool(new SocketFactory(POOL_SIZE,
                        url), POOL_SIZE);

And the SocketFactory is:

public class SocketFactory implements PoolableObjectFactory {

    /**
     * URL de conexión
     */
    private static String ENDPOINT = null; // 
Messages.getString("Connector.endpoint");

    /**
     * Contexto
     */
    private Context ctx;

    /**
     * Constructor.
     * 
     * @param poolSize
     *            Tamaño del pool
     * @param endpoint
     *            URL de conexión
     */
    public SocketFactory(int poolSize, final String endpoint) {
        ENDPOINT = endpoint;
        ctx = ZMQ.context(poolSize);
    }

    /**
     * {@inheritDoc}
     */
    public void activateObject(final Object obj) throws Exception {
        // En blanco
        System.out.println("activating");
    }

    /**
     * {@inheritDoc}
     */
    public void destroyObject(final Object obj) throws Exception {
        if (obj instanceof Socket) {
            Socket socket = (Socket) obj;
            socket.setLinger(0);
            socket.close();
            socket.disconnect(ENDPOINT);
            socket = null;
        }
    }

    /**
     * {@inheritDoc}
     */
    public Object makeObject() throws Exception {
        Socket socket = ctx.socket(ZMQ.REQ);
        socket.connect(ENDPOINT);
        return socket;
    }

    /**
     * {@inheritDoc}
     */
    public void passivateObject(final Object obj) throws Exception {
        // En blanco
        System.out.println("pss");
    }

    /**
     * {@inheritDoc}
     */
    public boolean validateObject(final Object obj) {
        Socket socket=(Socket) obj;
        return socket != null;
    }

}


Initially the code was getting hang / blocking a the req.recv() line, so I 
added the receive timeout to force errors when the server has problems, but 
then I came across the following message:

java.lang.IllegalStateException: Cannot send another request
        at zmq.Req.xsend(Req.java:51)
        at zmq.SocketBase.send(SocketBase.java:597)
        at org.zeromq.ZMQ$Socket.send(ZMQ.java:982)

I'm aware that this arises due to the fact that the socket is still in "recv" 
state, though it cannot send data, but upon object invalidation (when 
data==null) the sockets are closed, thus supossed to be reseted, but that 
doesn't seem to be working.

FYI: I'm using Java (quite obvious from above), but with JeroMQ SNAPSHOT 0.3.0

Any ideas on why the socket isn't being closed/reset? What am I doing wrong?

Regards,

Gonzalo Vásquez Sáez
Gerente Investigación y Desarrollo (R&D)
Altiuz Soluciones Tecnológicas de Negocios Ltda.
Av. Nueva Tajamar 555 Of. 802, Las Condes - CP 7550099
+56 2 335 2461
gvasq...@altiuz.cl
http://www.altiuz.cl
http://www.altiuzreports.com
  


_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to