Search in sources :

Example 11 with FilteringObjectInputStream

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

the class StreamMessageImpl method reset.

/**
 * Put the message body in read-only mode, and reposition the stream to the beginning.
 *
 * @exception JMSException if JMS fails to reset the message due to some internal JMS error.
 * @exception MessageFormatException if message has an invalid format
 */
@Override
public void reset() throws JMSException {
    try {
        if (bufferIsDirty) {
            objectOutputStream.flush();
            messageBody = byteArrayOutputStream.toByteArray();
            objectOutputStream.close();
            byteArrayOutputStream.close();
        }
        if (messageBody != null) {
            byteArrayInputStream = new ByteArrayInputStream(messageBody);
            objectInputStream = new FilteringObjectInputStream(byteArrayInputStream);
        }
    } catch (Exception e) {
        ExceptionHandler.handleException(e, AdministeredObject.cr.X_MESSAGE_RESET);
    }
    setBufferIsDirty(false);
    setMessageReadMode(true);
    // reset flag
    byteArrayReadState = false;
    notYetProcessedPrimitiveObject = null;
}
Also used : FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream)

Example 12 with FilteringObjectInputStream

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

the class Reader method run.

@Override
public void run() {
    try {
        ObjectInputStream dis = new FilteringObjectInputStream(is);
        int n = 0;
        while (MAX < 0 || n < MAX) {
            RandomBytes rb = (RandomBytes) dis.readObject();
            boolean valid = rb.isValid();
            int seq = rb.getSequence();
            if (seq != n) {
                System.out.println("#### PACKET OUT OF SEQUENCE ####");
                return;
            }
            if (VERBOSITY > 0) {
                System.out.println("#### Received packet #" + seq);
            }
            if (VERBOSITY > 1) {
                byte[] tmp = rb.getData();
                int len = tmp.length > 64 ? 64 : tmp.length;
                System.out.println("Bytes = " + new String(tmp, 1, len - 1));
                System.out.println("Length = " + (tmp.length - 1));
                System.out.println("Checksum = " + rb.getChecksum());
                System.out.println("Computed checksum = " + RandomBytes.computeChecksum(tmp));
                System.out.println("rb.isValid() = " + valid);
                System.out.println();
            }
            if (!valid) {
                System.out.println("#### CHECKSUM ERROR DETECTED ####");
                return;
            }
            n++;
            if (n % 100 == 0) {
                System.out.println("#### Free memory = " + Runtime.getRuntime().freeMemory());
                System.out.println("#### Total memory = " + Runtime.getRuntime().totalMemory());
                System.out.println();
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        s.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    System.out.println("#### Reader exiting...");
}
Also used : FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 13 with FilteringObjectInputStream

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

the class AdminCmdHandler method getBodyObject.

/**
 * Get object from the body of a packet
 */
protected Object getBodyObject(Packet pkt) {
    ObjectInputStream ois = null;
    Object o = null;
    // Extract the object from the message body
    try {
        ois = new FilteringObjectInputStream(pkt.getMessageBodyStream());
        o = ois.readObject();
    } catch (Exception e) {
        // Programing error. Do not need to localize
        logger.logStack(Logger.ERROR, rb.E_INTERNAL_BROKER_ERROR, this.getClass().getName() + " : Got exception reading body of administration message:\n" + e + "\n" + pkt.dumpPacketString(), e);
    } finally {
        if (ois != null) {
            try {
                ois.close();
            } catch (Exception e) {
            /* ignore */
            }
        }
    }
    return o;
}
Also used : FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 14 with FilteringObjectInputStream

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

the class JDBCTxLogImpl method logHeuristicBranch.

/**
 * @param bxid the branch xid to update
 * @param lr the LogRecord to identify the record to update
 */
@Override
public void logHeuristicBranch(BranchXid bxid, LogRecord lr) throws Exception {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "jdbcTxLog: log branch heuristic decision  " + lr);
    }
    final GlobalXid gxid = lr.getGlobalXid();
    final BranchXid branchXid = bxid;
    final LogRecord newlr = lr;
    super.checkClosedAndSetInProgress();
    try {
        UpdateOpaqueDataCallback callback = new UpdateOpaqueDataCallback() {

            @Override
            public Object update(Object currlr) throws Exception {
                ObjectInputStream ois = new FilteringObjectInputStream(new ByteArrayInputStream((byte[]) currlr));
                LogRecord oldlr = (LogRecord) ois.readObject();
                if (oldlr == null) {
                    throw new IllegalArgumentException("Unexpected null current log record for " + gxid);
                }
                if (!oldlr.getGlobalXid().equals(gxid)) {
                    throw new IllegalArgumentException("Unexpected global xid " + oldlr.getGlobalXid() + " from store, expected:" + gxid);
                }
                ois.close();
                if (oldlr.getBranchDecision(branchXid) == newlr.getBranchDecision(branchXid)) {
                    return currlr;
                }
                oldlr.setBranchDecision(branchXid, newlr.getBranchDecision(branchXid));
                return oldlr;
            }
        };
        _store.updateTMLogRecord(gxid.toString(), lr.toBytes(), _jmsbridge, callback, true, true, _logger);
    } finally {
        super.setInProgress(false);
    }
}
Also used : GlobalXid(com.sun.messaging.bridge.service.jms.tx.GlobalXid) ByteArrayInputStream(java.io.ByteArrayInputStream) UpdateOpaqueDataCallback(com.sun.messaging.bridge.api.UpdateOpaqueDataCallback) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) BranchXid(com.sun.messaging.bridge.service.jms.tx.BranchXid) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 15 with FilteringObjectInputStream

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

the class BaseTransaction method readFromBytes.

// io methods to read and write to byte array
public void readFromBytes(byte[] data) throws IOException, BrokerException {
    ByteArrayInputStream bais = new ByteArrayInputStream(data);
    DataInputStream dis = new DataInputStream(bais);
    readData(dis);
    int objectBodySize = dis.readInt();
    byte[] objectBody = new byte[objectBodySize];
    dis.read(objectBody);
    ByteArrayInputStream bais2 = new ByteArrayInputStream(objectBody);
    ObjectInputStream ois = new FilteringObjectInputStream(bais2);
    try {
        readObjects(ois);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    ois.close();
    bais2.close();
    dis.close();
    bais.close();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) DataInputStream(java.io.DataInputStream) FilteringObjectInputStream(com.sun.messaging.jmq.util.io.FilteringObjectInputStream) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

FilteringObjectInputStream (com.sun.messaging.jmq.util.io.FilteringObjectInputStream)22 ObjectInputStream (java.io.ObjectInputStream)13 ByteArrayInputStream (java.io.ByteArrayInputStream)12 DataInputStream (java.io.DataInputStream)5 Hashtable (java.util.Hashtable)5 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)2 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)2 TransactionWork (com.sun.messaging.jmq.jmsserver.data.TransactionWork)2 JMSException (jakarta.jms.JMSException)2 MessageFormatException (jakarta.jms.MessageFormatException)2 MessageNotWriteableException (jakarta.jms.MessageNotWriteableException)2 IOException (java.io.IOException)2 ByteBuffer (java.nio.ByteBuffer)2 HashMap (java.util.HashMap)2 UpdateOpaqueDataCallback (com.sun.messaging.bridge.api.UpdateOpaqueDataCallback)1 BranchXid (com.sun.messaging.bridge.service.jms.tx.BranchXid)1 GlobalXid (com.sun.messaging.bridge.service.jms.tx.GlobalXid)1 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)1 ClusterTransaction (com.sun.messaging.jmq.jmsserver.data.ClusterTransaction)1