Search in sources :

Example 1 with Task

use of org.apache.qpid.server.configuration.updater.Task in project qpid-broker-j by apache.

the class AbstractVirtualHost method importMessageStore.

@Override
public void importMessageStore(final String source) {
    try {
        final URL url = convertStringToURL(source);
        try (InputStream input = url.openStream();
            BufferedInputStream bufferedInputStream = new BufferedInputStream(input);
            DataInputStream data = new DataInputStream(bufferedInputStream)) {
            final MessageStoreSerializer serializer = MessageStoreSerializer.FACTORY.newInstance(data);
            doSync(doOnConfigThread(new Task<ListenableFuture<Void>, IOException>() {

                @Override
                public ListenableFuture<Void> execute() throws IOException {
                    if (getState() != State.STOPPED) {
                        throw new IllegalArgumentException("The importMessageStore operation can only be called when the virtual host is stopped");
                    }
                    try {
                        _messageStore.openMessageStore(AbstractVirtualHost.this);
                        checkMessageStoreEmpty();
                        final Map<String, UUID> queueMap = new HashMap<>();
                        getDurableConfigurationStore().reload(new ConfiguredObjectRecordHandler() {

                            @Override
                            public void handle(final ConfiguredObjectRecord record) {
                                if (record.getType().equals(Queue.class.getSimpleName())) {
                                    queueMap.put((String) record.getAttributes().get(ConfiguredObject.NAME), record.getId());
                                }
                            }
                        });
                        serializer.deserialize(queueMap, _messageStore, data);
                    } finally {
                        _messageStore.closeMessageStore();
                    }
                    return Futures.immediateFuture(null);
                }

                @Override
                public String getObject() {
                    return AbstractVirtualHost.this.toString();
                }

                @Override
                public String getAction() {
                    return "importMessageStore";
                }

                @Override
                public String getArguments() {
                    if (url.getProtocol().equalsIgnoreCase("http") || url.getProtocol().equalsIgnoreCase("https") || url.getProtocol().equalsIgnoreCase("file")) {
                        return "source=" + source;
                    } else if (url.getProtocol().equalsIgnoreCase("data")) {
                        return "source=<data stream>";
                    } else {
                        return "source=<unknown source type>";
                    }
                }
            }));
        }
    } catch (IOException e) {
        throw new IllegalConfigurationException("Cannot convert '" + source + "' to a readable resource", e);
    }
}
Also used : Task(org.apache.qpid.server.configuration.updater.Task) StatisticsReportingTask(org.apache.qpid.server.stats.StatisticsReportingTask) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BufferedInputStream(java.io.BufferedInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) IllegalConfigurationException(org.apache.qpid.server.configuration.IllegalConfigurationException) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) URL(java.net.URL) BufferedInputStream(java.io.BufferedInputStream) ConfiguredObjectRecord(org.apache.qpid.server.store.ConfiguredObjectRecord) MessageStoreSerializer(org.apache.qpid.server.store.serializer.MessageStoreSerializer) UUID(java.util.UUID) ConfiguredObjectRecordHandler(org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)

Example 2 with Task

use of org.apache.qpid.server.configuration.updater.Task in project qpid-broker-j by apache.

the class AbstractVirtualHost method purgeLinkRegistry.

@Override
public void purgeLinkRegistry(final String containerIdPatternString, final String role, final String linkNamePatternString) {
    doSync(doOnConfigThread(new Task<ListenableFuture<Void>, IOException>() {

        @Override
        public ListenableFuture<Void> execute() throws IOException {
            if (getState() != State.STOPPED) {
                throw new IllegalArgumentException("The purgeLinkRegistry operation can only be called when the virtual host is stopped.");
            }
            Pattern containerIdPattern = Pattern.compile(containerIdPatternString);
            Pattern linkNamePattern = Pattern.compile(linkNamePatternString);
            _messageStore.openMessageStore(AbstractVirtualHost.this);
            try {
                _linkRegistry.open();
                try {
                    if ("SENDER".equals(role) || "BOTH".equals(role)) {
                        _linkRegistry.purgeSendingLinks(containerIdPattern, linkNamePattern);
                    }
                    if ("RECEIVER".equals(role) || "BOTH".equals(role)) {
                        _linkRegistry.purgeReceivingLinks(containerIdPattern, linkNamePattern);
                    }
                    return Futures.immediateFuture(null);
                } finally {
                    _linkRegistry.close();
                }
            } finally {
                _messageStore.closeMessageStore();
            }
        }

        @Override
        public String getObject() {
            return AbstractVirtualHost.this.toString();
        }

        @Override
        public String getAction() {
            return "purgeLinkRegistry";
        }

        @Override
        public String getArguments() {
            return String.format("containerIdPattern='%s',role='%s',linkNamePattern='%s'", containerIdPatternString, role, linkNamePatternString);
        }
    }));
}
Also used : Pattern(java.util.regex.Pattern) Task(org.apache.qpid.server.configuration.updater.Task) StatisticsReportingTask(org.apache.qpid.server.stats.StatisticsReportingTask)

Aggregations

Task (org.apache.qpid.server.configuration.updater.Task)2 StatisticsReportingTask (org.apache.qpid.server.stats.StatisticsReportingTask)2 BufferedInputStream (java.io.BufferedInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 UUID (java.util.UUID)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Pattern (java.util.regex.Pattern)1 IllegalConfigurationException (org.apache.qpid.server.configuration.IllegalConfigurationException)1 ConfiguredObjectRecord (org.apache.qpid.server.store.ConfiguredObjectRecord)1 ConfiguredObjectRecordHandler (org.apache.qpid.server.store.handler.ConfiguredObjectRecordHandler)1 MessageStoreSerializer (org.apache.qpid.server.store.serializer.MessageStoreSerializer)1