Search in sources :

Example 1 with ReadWritePacket

use of com.sun.messaging.jmq.io.ReadWritePacket in project openmq by eclipse-ee4j.

the class IMQEmbeddedConnection method writeOutPacket.

@Override
protected boolean writeOutPacket(Packet p) throws IOException {
    // write packet
    // it needs to be of type ReadOnlyPacket
    ReadWritePacket rp = new ReadWritePacket();
    // this should be deep
    rp.fill(p, true);
    // stick on the queue
    outputQueue.add(rp);
    return true;
}
Also used : ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket)

Example 2 with ReadWritePacket

use of com.sun.messaging.jmq.io.ReadWritePacket in project openmq by eclipse-ee4j.

the class WebSocketConnectionHandler method readPacket.

@Override
public ReadWritePacket readPacket() throws IOException {
    ReadWritePacket pkt = null;
    synchronized (sessionLock) {
        if (session == null) {
            throw new IOException("WebSocket Session not open on JMS connection " + conn.getConnectionID());
        }
        String id = session.getId();
        while (!closed && packetRead == null) {
            if (logger.isLoggable(Level.FINE)) {
                logger.log(Level.FINE, "WebSocketConnectionHandler@" + hashCode() + ": readPacket() waiting for incoming packet, ws-session=" + id + " on JMS connection " + conn.getConnectionID());
            }
            try {
                sessionLock.wait();
            } catch (InterruptedException e) {
            }
        }
        if (closed) {
            throw new IOException(AdministeredObject.cr.getKString(AdministeredObject.cr.X_WEBSOCKET_SESSION_CLOSED));
        }
        pkt = packetRead;
        packetRead = null;
        sessionLock.notifyAll();
    }
    if (logger.isLoggable(Level.FINEST)) {
        logger.log(Level.FINEST, "WebSocketConnectionHandler@" + hashCode() + ": READ PACKET=" + pkt + ", ws-session=" + session.getId() + ", on JMS connection " + conn.getConnectionID());
    }
    return pkt;
}
Also used : ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket) IOException(java.io.IOException)

Example 3 with ReadWritePacket

use of com.sun.messaging.jmq.io.ReadWritePacket in project openmq by eclipse-ee4j.

the class WebSocketConnectionHandler method onMessage.

/**
 *****************************************************
 * Implement MessageHandler.Whole interface
 **********************************************************
 */
/**
 * Called when the message has been fully received.
 *
 * @param data the message data.
 */
@Override
public void onMessage(ByteBuffer data) {
    if (logger.isLoggable(Level.FINEST)) {
        Session ss = session;
        logger.log(Level.FINEST, Thread.currentThread() + "WebSocketConnectionHandler@" + hashCode() + ": onMessage(ByteBuffer@" + data.hashCode() + "[len=" + data.remaining() + ", pos=" + data.position() + "]), ws-session=" + (ss == null ? "null" : ss.getId()) + " on JMS connection " + conn.getConnectionID());
    }
    String id = null;
    while (data.hasRemaining()) {
        synchronized (sessionLock) {
            if (session == null) {
                throw new IllegalStateException("WebSocket Session not open on JMS connection " + conn.getConnectionID());
            }
            id = session.getId();
            while (!closed && packetRead != null) {
                if (logger.isLoggable(Level.FINE)) {
                    logger.log(Level.FINE, Thread.currentThread() + "WebSocketConnectionHandler@" + hashCode() + ": onMessage() waiting for packet read to be dispatched, ws-session=" + id + " on JMS connection " + conn.getConnectionID());
                }
                try {
                    sessionLock.wait();
                } catch (InterruptedException e) {
                }
            }
            if (closed) {
                throw new IllegalStateException(AdministeredObject.cr.getKString(AdministeredObject.cr.X_WEBSOCKET_SESSION_CLOSED));
            }
            if (packetPending == null) {
                packetPending = new ReadWritePacket();
            }
        }
        try {
            if (packetPending.readPacket(data)) {
                if (!packetPending.hasBigPacketException()) {
                    synchronized (sessionLock) {
                        packetRead = packetPending;
                        packetPending = null;
                        sessionLock.notifyAll();
                    }
                    if (logger.isLoggable(Level.FINEST)) {
                        logger.log(Level.FINEST, Thread.currentThread() + "WebSocketConnectionHandler@" + hashCode() + ": onMessage(): RECEIVED PACKET=" + packetPending + ", remaining=" + data.remaining() + ",ws-session=" + id + " on JMS connection " + conn.getConnectionID());
                    }
                } else {
                    IOException ioe = packetPending.getBigPacketException();
                    packetPending = null;
                    throw new IOException("BigPacketException", ioe);
                }
            }
        } catch (BigPacketException e) {
            String[] params = { (packetPending == null ? "(r):" + packetRead : "(p):" + packetPending), this.toString(), e.getMessage() };
            String emsg = AdministeredObject.cr.getKString(AdministeredObject.cr.X_WEBSOCKET_PROCESS_PKT, params);
            logger.log(Level.SEVERE, emsg);
        } catch (IOException e) {
            onError(session, e);
            String[] params = { (packetPending == null ? "(r):" + packetRead : "(p):" + packetPending), this.toString(), e.getMessage() };
            throw new RuntimeException(AdministeredObject.cr.getKString(AdministeredObject.cr.X_WEBSOCKET_PROCESS_PKT, params), e);
        }
    }
}
Also used : BigPacketException(com.sun.messaging.jmq.io.BigPacketException) ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket) IOException(java.io.IOException) Session(jakarta.websocket.Session)

Example 4 with ReadWritePacket

use of com.sun.messaging.jmq.io.ReadWritePacket in project openmq by eclipse-ee4j.

the class DirectConnectionHandler method writePacket.

@Override
public void writePacket(ReadWritePacket pkt) throws IOException {
    try {
        if (isClosed) {
            throw new IOException("Connection is closed.");
        }
        pkt.updateSequenceNumber();
        pkt.updateTimestamp();
        pkt.updateBuffers();
        ReadWritePacket newPkt = (ReadWritePacket) pkt.clone();
        this.outBoundQ.put(newPkt);
        if (directDebug) {
            System.out.println("Direct connection wrote pkt..." + newPkt);
            // pkt.dump(System.out);
            System.out.flush();
        }
    } catch (IOException ioe) {
        throw ioe;
    } catch (Exception e) {
        IOException ioe = new IOException(e.getMessage());
        throw ioe;
    }
// XXX write to inbound for short-circuit client only testing
// this.inBoundQ.put(newPkt);
}
Also used : ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket) IOException(java.io.IOException) JMSException(jakarta.jms.JMSException) IOException(java.io.IOException)

Example 5 with ReadWritePacket

use of com.sun.messaging.jmq.io.ReadWritePacket in project openmq by eclipse-ee4j.

the class SocketConnectionHandler method readPacket.

@Override
public ReadWritePacket readPacket() throws IOException {
    ReadWritePacket pkt = new ReadWritePacket();
    pkt.readPacket(is);
    return pkt;
}
Also used : ReadWritePacket(com.sun.messaging.jmq.io.ReadWritePacket)

Aggregations

ReadWritePacket (com.sun.messaging.jmq.io.ReadWritePacket)9 IOException (java.io.IOException)6 JMSException (jakarta.jms.JMSException)2 BigPacketException (com.sun.messaging.jmq.io.BigPacketException)1 Packet (com.sun.messaging.jmq.io.Packet)1 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 Session (jakarta.websocket.Session)1