Search in sources :

Example 26 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class InterestStore method removeInterest.

/**
 * Remove the interest from the persistent store.
 *
 * @param interest the interest to be removed
 * @exception IOException if an error occurs while removing the interest
 * @exception BrokerException if the interest is not found in the store
 */
void removeInterest(Consumer interest, boolean sync) throws IOException, BrokerException {
    Object oldinterest = null;
    ConsumerUID id = interest.getConsumerUID();
    try {
        oldinterest = interestMap.remove(id);
        if (oldinterest == null) {
            logger.log(logger.ERROR, br.E_INTEREST_NOT_FOUND_IN_STORE, id, interest.getDestinationUID().getLongString());
            throw new BrokerException(br.getString(br.E_INTEREST_NOT_FOUND_IN_STORE, id, interest.getDestinationUID().getLongString()));
        }
        if (sync) {
            sync();
        }
    } catch (RuntimeException e) {
        logger.log(logger.ERROR, br.X_REMOVE_INTEREST_FAILED, id);
        throw new BrokerException(br.getString(br.X_REMOVE_INTEREST_FAILED, id), e);
    }
}
Also used : ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID)

Example 27 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class MessageInfo method parseInterestList.

// load states from byte array
// format:
// number of entries (int)
// fixed length entries (iid, state)
private void parseInterestList(byte[] buf) throws IOException {
    if (buf == null || buf.length == 0) {
        if (Store.getDEBUG() && DEBUG) {
            logger.log(logger.INFO, "No interest list to load");
        }
        // nothing to load
        return;
    }
    ByteArrayInputStream bis = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(bis);
    // read in number of entries
    int size = dis.readInt();
    iidMap = new HashMap(size);
    statearray = new int[size];
    for (int i = 0; i < size; i++) {
        ConsumerUID iid = new ConsumerUID(dis.readLong());
        statearray[i] = dis.readInt();
        // put in interest id map
        iidMap.put(iid, Integer.valueOf(i));
    }
    dis.close();
    bis.close();
    if (Store.getDEBUG() && DEBUG) {
        logger.log(logger.INFO, "loaded " + size + " interest states");
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) DataInputStream(java.io.DataInputStream)

Example 28 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class MessageInfo method getConsumerUIDs.

/**
 * Return ConsumerUIDs whose associated state is not INTEREST_STATE_ACKNOWLEDGED.
 */
synchronized ConsumerUID[] getConsumerUIDs() {
    ConsumerUID[] ids = new ConsumerUID[0];
    if (iidMap != null) {
        ArrayList list = new ArrayList();
        Set entries = iidMap.entrySet();
        Iterator itor = entries.iterator();
        while (itor.hasNext()) {
            Map.Entry entry = (Map.Entry) itor.next();
            Integer index = (Integer) entry.getValue();
            if (statearray[index.intValue()] != PartitionedStore.INTEREST_STATE_ACKNOWLEDGED) {
                list.add(entry.getKey());
            }
        }
        ids = (ConsumerUID[]) list.toArray(ids);
    }
    return ids;
}
Also used : Set(java.util.Set) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class MessageInfo method parseInterestList.

// load states from backing buffer
// format:
// number of entries (int)
// fixed length entries (iid (long), state (int))
private void parseInterestList(VRecordRAF r) throws IOException {
    int size = 0;
    try {
        // position after the size of message and the message
        r.position(INT_SIZE + packetSize);
        // read in number of entries
        size = r.readInt();
        // sanity check
        long endofrec = INT_SIZE + packetSize + INT_SIZE + ((long) size * ENTRY_SIZE);
        if (endofrec > r.getDataCapacity()) {
            throw new Exception("size of interest list is corrupted");
        }
        iidMap = new HashMap(size);
        statearray = new int[size];
        for (int i = 0; i < size; i++) {
            ConsumerUID iid = new ConsumerUID(r.readLong());
            statearray[i] = r.readInt();
            // put in interest id map
            iidMap.put(iid, Integer.valueOf(i));
        }
        if (Store.getDEBUG() && DEBUG) {
            logger.log(logger.INFO, "loaded " + size + " interest states");
        }
    } catch (Throwable t) {
        logger.log(logger.ERROR, "failed to parse interest list(size=" + size + ") for msg(size=" + packetSize + ") from vrecord(" + r + ")", t);
        IOException e = new IOException(t.toString());
        e.setStackTrace(t.getStackTrace());
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) IOException(java.io.IOException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException)

Example 30 with ConsumerUID

use of com.sun.messaging.jmq.jmsserver.core.ConsumerUID in project openmq by eclipse-ee4j.

the class ConsumerDAOImpl method insert.

/**
 * Insert a new entry.
 *
 * @param conn database connection
 * @param consumer the Consumer
 * @param createdTS timestamp
 * @throws BrokerException if entry exists in the store already
 */
@Override
public void insert(Connection conn, Consumer consumer, long createdTS) throws BrokerException {
    ConsumerUID consumerUID = consumer.getConsumerUID();
    String durableName = null;
    String clientID = null;
    if (consumer instanceof Subscription) {
        Subscription sub = (Subscription) consumer;
        durableName = sub.getDurableName();
        clientID = sub.getClientID();
    }
    boolean myConn = false;
    String sql = insertSQL;
    PreparedStatement pstmt = null;
    Exception myex = null;
    try {
        DBManager dbMgr = DBManager.getDBManager();
        if (conn == null) {
            conn = dbMgr.getConnection(true);
            myConn = true;
        }
        Consumer tmpc = checkConsumer(conn, consumer, true);
        if (tmpc != null) {
            throwConflictException(tmpc, consumer);
        }
        if (durableName != null) {
            tmpc = checkConsumer(conn, consumer, false);
            if (tmpc != null) {
                throwConflictException(tmpc, consumer);
            }
        }
        if (durableName != null && !dbMgr.isDB2()) {
            sql = insertNoDupSQL;
        }
        pstmt = dbMgr.createPreparedStatement(conn, sql);
        pstmt.setLong(1, consumerUID.longValue());
        Util.setObject(pstmt, 2, consumer);
        Util.setString(pstmt, 3, durableName);
        Util.setString(pstmt, 4, clientID, false);
        pstmt.setLong(5, createdTS);
        if (durableName != null && !dbMgr.isDB2()) {
            Util.setString(pstmt, 6, durableName);
            Util.setString(pstmt, 7, clientID, false);
        }
        if (pstmt.executeUpdate() == 0) {
            tmpc = checkConsumer(conn, consumer, true);
            if (tmpc != null) {
                throwConflictException(tmpc, consumer);
            }
            if (durableName != null) {
                tmpc = checkConsumer(conn, consumer, false);
                if (tmpc != null) {
                    throwConflictException(tmpc, consumer);
                }
            }
            throw new BrokerException(br.getKString(BrokerResources.X_PERSIST_INTEREST_FAILED, consumerUID));
        }
    } catch (Exception e) {
        myex = e;
        try {
            if ((conn != null) && !conn.getAutoCommit()) {
                conn.rollback();
            }
        } catch (SQLException rbe) {
            logger.log(Logger.ERROR, BrokerResources.X_DB_ROLLBACK_FAILED, rbe);
        }
        Exception ex;
        if (e instanceof BrokerException) {
            throw (BrokerException) e;
        } else if (e instanceof IOException) {
            ex = DBManager.wrapIOException("[" + sql + "]", (IOException) e);
        } else if (e instanceof SQLException) {
            ex = DBManager.wrapSQLException("[" + sql + "]", (SQLException) e);
        } else {
            ex = e;
        }
        throw new BrokerException(br.getKString(BrokerResources.X_PERSIST_INTEREST_FAILED, consumerUID), ex);
    } finally {
        if (myConn) {
            Util.close(null, pstmt, conn, myex);
        } else {
            Util.close(null, pstmt, null, myex);
        }
    }
}
Also used : Consumer(com.sun.messaging.jmq.jmsserver.core.Consumer) ConsumerUID(com.sun.messaging.jmq.jmsserver.core.ConsumerUID) IOException(java.io.IOException) Subscription(com.sun.messaging.jmq.jmsserver.core.Subscription) IOException(java.io.IOException)

Aggregations

ConsumerUID (com.sun.messaging.jmq.jmsserver.core.ConsumerUID)83 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)29 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)28 Consumer (com.sun.messaging.jmq.jmsserver.core.Consumer)27 DestinationUID (com.sun.messaging.jmq.jmsserver.core.DestinationUID)22 PacketReference (com.sun.messaging.jmq.jmsserver.core.PacketReference)21 SelectorFormatException (com.sun.messaging.jmq.util.selector.SelectorFormatException)21 Iterator (java.util.Iterator)21 HashMap (java.util.HashMap)19 Destination (com.sun.messaging.jmq.jmsserver.core.Destination)17 TransactionUID (com.sun.messaging.jmq.jmsserver.data.TransactionUID)16 IOException (java.io.IOException)16 ArrayList (java.util.ArrayList)15 Map (java.util.Map)15 List (java.util.List)13 BrokerAddress (com.sun.messaging.jmq.jmsserver.core.BrokerAddress)10 DestinationList (com.sun.messaging.jmq.jmsserver.core.DestinationList)10 Session (com.sun.messaging.jmq.jmsserver.core.Session)10 TransactionList (com.sun.messaging.jmq.jmsserver.data.TransactionList)10 AckEntryNotFoundException (com.sun.messaging.jmq.jmsserver.util.AckEntryNotFoundException)9