use of org.apache.qpid.server.store.serializer.MessageStoreSerializer 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);
}
}
Aggregations