Package com.sleepycat.je

Examples of com.sleepycat.je.SecondaryCursor


    }


    public void recoverSubscription(Subscription subscription, MessageIdentity lastDispatchedMessage) throws JMSException {
        checkClosed();
        SecondaryCursor cursor = null;
        try {
            DatabaseEntry lastAckKey = getLastAcknowledgedMessageID(subscription, lastDispatchedMessage);
            if (lastAckKey != null) {
                cursor = getSecondaryDatabase().openSecondaryCursor(BDbHelper.getTransaction(), getCursorConfig());
                DatabaseEntry valueEntry = new DatabaseEntry();
                OperationStatus status = cursor.getSearchKey(lastAckKey, valueEntry, LockMode.DEFAULT);
                if (status != OperationStatus.SUCCESS) {
                    log.error("Could not find the last acknowledged record for: " + subscription + ". Status: " + status);
                }
                else {
                    while (true) {
                        // lets pass straight over the first entry, which we've already ack'd
                        status = cursor.getNext(lastAckKey, valueEntry, LockMode.DEFAULT);
                        if (status != OperationStatus.SUCCESS) {
                            if (status != OperationStatus.NOTFOUND) {
                                log.warn("Strange result when iterating to end of collection: " + status);
                            }
                            break;
                        }

                        ActiveMQMessage message = extractMessage(valueEntry);
                        subscription.addMessage(getContainer(), message);
                    }
                }
            }
        }
        catch (DatabaseException e) {
            throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
                    + subscription + ". Reason: " + e, e);
        }
        catch (IOException e) {
            throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
                    + subscription + ". Reason: " + e, e);
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here


        }
    }

    public MessageIdentity getLastestMessageIdentity() throws JMSException {
        checkClosed();
        SecondaryCursor cursor = null;
        try {
            cursor = getSecondaryDatabase().openSecondaryCursor(BDbHelper.getTransaction(), getCursorConfig());
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getLast(keyEntry, valueEntry, LockMode.DEFAULT);
            if (status == OperationStatus.SUCCESS) {
                if (log.isDebugEnabled()) {
                    log.debug("Loaded last sequence number of: " + BDbHelper.longFromBytes(keyEntry.getData()));
                }
                return new MessageIdentity(null, keyEntry);
            }
            else if (status != OperationStatus.NOTFOUND) {
                log.error("Could not find the last sequence number. Status: " + status);
            }
            return null;
        }
        catch (DatabaseException e) {
            throw JMSExceptionHelper.newJMSException("Unable to load the last sequence number. Reason: " + e, e);
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here

        final DatabaseEntry sKey = new DatabaseEntry(Shorts.toByteArray(node));
        final DatabaseEntry pKey = new DatabaseEntry();
        final DatabaseEntry data = new DatabaseEntry();

        final SecondaryCursor cursor = ownerIndex.openCursor(txn, null);
        try {
            OperationStatus retVal = cursor.getSearchKey(sKey, pKey, data, LockMode.DEFAULT);
            while (retVal == OperationStatus.SUCCESS) {
                final long id = Longs.fromByteArray(pKey.getData());
                if (trace)
                    LOG.trace("Owner of {}: {} -> 0", id, node);

                lines.add(id); // cursor.getPrimaryDatabase().put(null, pKey, SERVER); - causes deadlock
                retVal = cursor.getNextDup(sKey, pKey, data, LockMode.DEFAULT);
            }
        } finally {
            cursor.close();
        }

        byte[] longArray = new byte[8];
        for (TLongIterator it = lines.iterator(); it.hasNext();) {
            toByteArray(it.next(), longArray);
View Full Code Here

        ps.println("OWNER INDEX");
        ps.println("===========");
        final DatabaseEntry sKey = new DatabaseEntry();
        final DatabaseEntry pKey = new DatabaseEntry();
        final DatabaseEntry value = new DatabaseEntry();
        final SecondaryCursor cursor = ownerIndex.openCursor(null, CursorConfig.DEFAULT);
        try {
            while (cursor.getNext(sKey, pKey, value, LockMode.DEFAULT) == OperationStatus.SUCCESS) {
                long id = Longs.fromByteArray(pKey.getData());
                short owner = Shorts.fromByteArray(sKey.getData());
                ps.println("Owner: " + owner + " id : " + hex(id));
            }
        } finally {
            cursor.close();
        }
    }
View Full Code Here

        this.deleteKeyStore.set(nextKey);
    }

    protected long queryLatestKeyInDatabase(SecondaryDatabase database) throws JMSException, DatabaseException {
        CursorConfig cursorConfig = null;
        SecondaryCursor cursor = null;
        try {
            cursor = database.openSecondaryCursor(BDbHelper.getTransaction(), cursorConfig);
            DatabaseEntry sequenceNumberEntry = new DatabaseEntry();
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getLast(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            long answer = 1;
            if (status != OperationStatus.NOTFOUND) {
                if (status == OperationStatus.SUCCESS) {
                    answer = extractLong(sequenceNumberEntry);
                }
                else {
                    throw new JMSException("Invalid status code: " + status + " cannot read last sequence number");
                }
            }
            return answer;
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Error closing cursor: " + e, e);
                }
            }
View Full Code Here

        }
    }

    public void recover(RecoveryListener listener) throws JMSException {
        checkClosed();
        SecondaryCursor cursor = null;
        try {
            cursor = secondaryDatabase.openSecondaryCursor(BDbHelper.getTransaction(), cursorConfig);
            DatabaseEntry sequenceNumberEntry = new DatabaseEntry();
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getFirst(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            while (status == OperationStatus.SUCCESS) {
                String messageID = extractString(keyEntry);
                listener.recoverMessage(new MessageIdentity(messageID, sequenceNumberEntry));
                status = cursor.getNext(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            }
            if (status != OperationStatus.NOTFOUND) {
                log.warn("Unexpected status code while recovering: " + status);
            }
        }
        catch (DatabaseException e) {
            throw JMSExceptionHelper.newJMSException("Failed to recover container. Reason: " + e, e);
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here

     * @return
     */
    protected DatabaseEntry findSequenceNumber(String messageID) throws DatabaseException {
        log.warn("Having to table scan to find the sequence number for messageID: " + messageID);

        SecondaryCursor cursor = null;
        try {
            cursor = secondaryDatabase.openSecondaryCursor(BDbHelper.getTransaction(), cursorConfig);
            DatabaseEntry sequenceNumberEntry = new DatabaseEntry();
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getFirst(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            while (status == OperationStatus.SUCCESS) {
                String value = extractString(keyEntry);
                if (messageID.equals(value)) {
                    return sequenceNumberEntry;
                }
                status = cursor.getNext(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            }
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here

    }


    public void recoverSubscription(Subscription subscription, MessageIdentity lastDispatchedMessage) throws JMSException {
        checkClosed();
        SecondaryCursor cursor = null;
        try {
            DatabaseEntry lastAckKey = getLastAcknowledgedMessageID(subscription, lastDispatchedMessage);
            if (lastAckKey != null) {
                cursor = getSecondaryDatabase().openSecondaryCursor(BDbHelper.getTransaction(), getCursorConfig());
                DatabaseEntry valueEntry = new DatabaseEntry();
                OperationStatus status = cursor.getSearchKey(lastAckKey, valueEntry, LockMode.DEFAULT);
                if (status != OperationStatus.SUCCESS) {
                    log.error("Could not find the last acknowledged record for: " + subscription + ". Status: " + status);
                }
                else {
                    while (true) {
                        // lets pass straight over the first entry, which we've already ack'd
                        status = cursor.getNext(lastAckKey, valueEntry, LockMode.DEFAULT);
                        if (status != OperationStatus.SUCCESS) {
                            if (status != OperationStatus.NOTFOUND) {
                                log.warn("Strange result when iterating to end of collection: " + status);
                            }
                            break;
                        }

                        ActiveMQMessage message = extractMessage(valueEntry);
                        subscription.addMessage(getContainer(), message);
                    }
                }
            }
        }
        catch (DatabaseException e) {
            throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
                    + subscription + ". Reason: " + e, e);
        }
        catch (IOException e) {
            throw JMSExceptionHelper.newJMSException("Unable to recover topic subscription for: "
                    + subscription + ". Reason: " + e, e);
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here

        }
    }

    public MessageIdentity getLastestMessageIdentity() throws JMSException {
        checkClosed();
        SecondaryCursor cursor = null;
        try {
            cursor = getSecondaryDatabase().openSecondaryCursor(BDbHelper.getTransaction(), getCursorConfig());
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getLast(keyEntry, valueEntry, LockMode.DEFAULT);
            if (status == OperationStatus.SUCCESS) {
                if (log.isDebugEnabled()) {
                    log.debug("Loaded last sequence number of: " + BDbHelper.longFromBytes(keyEntry.getData()));
                }
                return new MessageIdentity(null, keyEntry);
            }
            else if (status != OperationStatus.NOTFOUND) {
                log.error("Could not find the last sequence number. Status: " + status);
            }
            return null;
        }
        catch (DatabaseException e) {
            throw JMSExceptionHelper.newJMSException("Unable to load the last sequence number. Reason: " + e, e);
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Caught exception closing cursor: " + e, e);
                }
            }
View Full Code Here

        this.deleteKeyStore.set(nextKey);
    }

    protected long queryLatestKeyInDatabase(SecondaryDatabase database) throws JMSException, DatabaseException {
        CursorConfig cursorConfig = null;
        SecondaryCursor cursor = null;
        try {
            cursor = database.openSecondaryCursor(BDbHelper.getTransaction(), cursorConfig);
            DatabaseEntry sequenceNumberEntry = new DatabaseEntry();
            DatabaseEntry keyEntry = new DatabaseEntry();
            DatabaseEntry valueEntry = new DatabaseEntry();
            OperationStatus status = cursor.getLast(sequenceNumberEntry, keyEntry, valueEntry, LockMode.DEFAULT);
            long answer = 1;
            if (status != OperationStatus.NOTFOUND) {
                if (status == OperationStatus.SUCCESS) {
                    answer = extractLong(sequenceNumberEntry);
                }
                else {
                    throw new JMSException("Invalid status code: " + status + " cannot read last sequence number");
                }
            }
            return answer;
        }
        finally {
            if (cursor != null) {
                try {
                    cursor.close();
                }
                catch (DatabaseException e) {
                    log.warn("Error closing cursor: " + e, e);
                }
            }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.SecondaryCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.