mirror of https://github.com/apache/activemq.git
Add warning about long destination names and mKahaDB for:
https://issues.apache.org/jira/browse/AMQ-4183 git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1420778 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fbc4c17ca2
commit
05fb2bbcc9
|
@ -16,18 +16,26 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.activemq.util;
|
package org.apache.activemq.util;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class IOHelper {
|
public final class IOHelper {
|
||||||
|
|
||||||
protected static final int MAX_DIR_NAME_LENGTH;
|
protected static final int MAX_DIR_NAME_LENGTH;
|
||||||
protected static final int MAX_FILE_NAME_LENGTH;
|
protected static final int MAX_FILE_NAME_LENGTH;
|
||||||
private static final int DEFAULT_BUFFER_SIZE = 4096;
|
private static final int DEFAULT_BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
private IOHelper() {
|
private IOHelper() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,18 +70,18 @@ public final class IOHelper {
|
||||||
public static String toFileSystemDirectorySafeName(String name) {
|
public static String toFileSystemDirectorySafeName(String name) {
|
||||||
return toFileSystemSafeName(name, true, MAX_DIR_NAME_LENGTH);
|
return toFileSystemSafeName(name, true, MAX_DIR_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String toFileSystemSafeName(String name) {
|
public static String toFileSystemSafeName(String name) {
|
||||||
return toFileSystemSafeName(name, false, MAX_FILE_NAME_LENGTH);
|
return toFileSystemSafeName(name, false, MAX_FILE_NAME_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts any string into a string that is safe to use as a file name.
|
* Converts any string into a string that is safe to use as a file name.
|
||||||
* The result will only include ascii characters and numbers, and the "-","_", and "." characters.
|
* The result will only include ascii characters and numbers, and the "-","_", and "." characters.
|
||||||
*
|
*
|
||||||
* @param name
|
* @param name
|
||||||
* @param dirSeparators
|
* @param dirSeparators
|
||||||
* @param maxFileLength
|
* @param maxFileLength
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String toFileSystemSafeName(String name,boolean dirSeparators,int maxFileLength) {
|
public static String toFileSystemSafeName(String name,boolean dirSeparators,int maxFileLength) {
|
||||||
|
@ -147,7 +155,7 @@ public final class IOHelper {
|
||||||
result &= fileToDelete.delete();
|
result &= fileToDelete.delete();
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteChildren(File parent) {
|
public static boolean deleteChildren(File parent) {
|
||||||
if (parent == null || !parent.exists()) {
|
if (parent == null || !parent.exists()) {
|
||||||
return false;
|
return false;
|
||||||
|
@ -172,21 +180,20 @@ public final class IOHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void moveFile(File src, File targetDirectory) throws IOException {
|
public static void moveFile(File src, File targetDirectory) throws IOException {
|
||||||
if (!src.renameTo(new File(targetDirectory, src.getName()))) {
|
if (!src.renameTo(new File(targetDirectory, src.getName()))) {
|
||||||
throw new IOException("Failed to move " + src + " to " + targetDirectory);
|
throw new IOException("Failed to move " + src + " to " + targetDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyFile(File src, File dest) throws IOException {
|
public static void copyFile(File src, File dest) throws IOException {
|
||||||
copyFile(src, dest, null);
|
copyFile(src, dest, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyFile(File src, File dest, FilenameFilter filter) throws IOException {
|
public static void copyFile(File src, File dest, FilenameFilter filter) throws IOException {
|
||||||
if (src.getCanonicalPath().equals(dest.getCanonicalPath()) == false) {
|
if (src.getCanonicalPath().equals(dest.getCanonicalPath()) == false) {
|
||||||
if (src.isDirectory()) {
|
if (src.isDirectory()) {
|
||||||
|
@ -209,7 +216,7 @@ public final class IOHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static File getCopyParent(File from, File to, File src) {
|
static File getCopyParent(File from, File to, File src) {
|
||||||
File result = null;
|
File result = null;
|
||||||
File parent = src.getParentFile();
|
File parent = src.getParentFile();
|
||||||
|
@ -224,13 +231,13 @@ public final class IOHelper {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static List<File> getFiles(File dir,FilenameFilter filter){
|
static List<File> getFiles(File dir,FilenameFilter filter){
|
||||||
List<File> result = new ArrayList<File>();
|
List<File> result = new ArrayList<File>();
|
||||||
getFiles(dir,result,filter);
|
getFiles(dir,result,filter);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void getFiles(File dir,List<File> list,FilenameFilter filter) {
|
static void getFiles(File dir,List<File> list,FilenameFilter filter) {
|
||||||
if (!list.contains(dir)) {
|
if (!list.contains(dir)) {
|
||||||
list.add(dir);
|
list.add(dir);
|
||||||
|
@ -245,14 +252,13 @@ public final class IOHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void copySingleFile(File src, File dest) throws IOException {
|
public static void copySingleFile(File src, File dest) throws IOException {
|
||||||
FileInputStream fileSrc = new FileInputStream(src);
|
FileInputStream fileSrc = new FileInputStream(src);
|
||||||
FileOutputStream fileDest = new FileOutputStream(dest);
|
FileOutputStream fileDest = new FileOutputStream(dest);
|
||||||
copyInputStream(fileSrc, fileDest);
|
copyInputStream(fileSrc, fileDest);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void copyInputStream(InputStream in, OutputStream out) throws IOException {
|
public static void copyInputStream(InputStream in, OutputStream out) throws IOException {
|
||||||
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
||||||
int len = in.read(buffer);
|
int len = in.read(buffer);
|
||||||
|
@ -263,19 +269,26 @@ public final class IOHelper {
|
||||||
in.close();
|
in.close();
|
||||||
out.close();
|
out.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
MAX_DIR_NAME_LENGTH = Integer.getInteger("MaximumDirNameLength",200);
|
MAX_DIR_NAME_LENGTH = Integer.getInteger("MaximumDirNameLength", 200);
|
||||||
MAX_FILE_NAME_LENGTH = Integer.getInteger("MaximumFileNameLength",64);
|
MAX_FILE_NAME_LENGTH = Integer.getInteger("MaximumFileNameLength", 64);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxDirNameLength() {
|
||||||
|
return MAX_DIR_NAME_LENGTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getMaxFileNameLength() {
|
||||||
|
return MAX_FILE_NAME_LENGTH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void mkdirs(File dir) throws IOException {
|
public static void mkdirs(File dir) throws IOException {
|
||||||
if (dir.exists()) {
|
if (dir.exists()) {
|
||||||
if (!dir.isDirectory()) {
|
if (!dir.isDirectory()) {
|
||||||
throw new IOException("Failed to create directory '" + dir +"', regular file already existed with that name");
|
throw new IOException("Failed to create directory '" + dir +"', regular file already existed with that name");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
if (!dir.mkdirs()) {
|
if (!dir.mkdirs()) {
|
||||||
throw new IOException("Failed to create directory '" + dir+"'");
|
throw new IOException("Failed to create directory '" + dir+"'");
|
||||||
|
|
|
@ -124,6 +124,12 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
}
|
}
|
||||||
|
|
||||||
private String nameFromDestinationFilter(ActiveMQDestination destination) {
|
private String nameFromDestinationFilter(ActiveMQDestination destination) {
|
||||||
|
|
||||||
|
if (destination.getQualifiedName().length() > IOHelper.getMaxFileNameLength()) {
|
||||||
|
LOG.warn("Destination name is longer than 'MaximumFileNameLength' system property, " +
|
||||||
|
"potential problem with recovery can result from name truncation.");
|
||||||
|
}
|
||||||
|
|
||||||
return IOHelper.toFileSystemSafeName(destination.getQualifiedName());
|
return IOHelper.toFileSystemSafeName(destination.getQualifiedName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,20 +138,24 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
((XATransactionId)xid).getFormatId() == LOCAL_FORMAT_ID_MAGIC;
|
((XATransactionId)xid).getFormatId() == LOCAL_FORMAT_ID_MAGIC;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void beginTransaction(ConnectionContext context) throws IOException {
|
public void beginTransaction(ConnectionContext context) throws IOException {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void checkpoint(final boolean sync) throws IOException {
|
public void checkpoint(final boolean sync) throws IOException {
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.checkpoint(sync);
|
persistenceAdapter.checkpoint(sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void commitTransaction(ConnectionContext context) throws IOException {
|
public void commitTransaction(ConnectionContext context) throws IOException {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException {
|
public MessageStore createQueueMessageStore(ActiveMQQueue destination) throws IOException {
|
||||||
PersistenceAdapter persistenceAdapter = getMatchingPersistenceAdapter(destination);
|
PersistenceAdapter persistenceAdapter = getMatchingPersistenceAdapter(destination);
|
||||||
return transactionStore.proxy(persistenceAdapter.createTransactionStore(), persistenceAdapter.createQueueMessageStore(destination));
|
return transactionStore.proxy(persistenceAdapter.createTransactionStore(), persistenceAdapter.createQueueMessageStore(destination));
|
||||||
|
@ -187,15 +197,18 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException {
|
public TopicMessageStore createTopicMessageStore(ActiveMQTopic destination) throws IOException {
|
||||||
PersistenceAdapter persistenceAdapter = getMatchingPersistenceAdapter(destination);
|
PersistenceAdapter persistenceAdapter = getMatchingPersistenceAdapter(destination);
|
||||||
return transactionStore.proxy(persistenceAdapter.createTransactionStore(), persistenceAdapter.createTopicMessageStore(destination));
|
return transactionStore.proxy(persistenceAdapter.createTransactionStore(), persistenceAdapter.createTopicMessageStore(destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public TransactionStore createTransactionStore() throws IOException {
|
public TransactionStore createTransactionStore() throws IOException {
|
||||||
return transactionStore;
|
return transactionStore;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void deleteAllMessages() throws IOException {
|
public void deleteAllMessages() throws IOException {
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.deleteAllMessages();
|
persistenceAdapter.deleteAllMessages();
|
||||||
|
@ -204,6 +217,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
IOHelper.deleteChildren(getDirectory());
|
IOHelper.deleteChildren(getDirectory());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Set<ActiveMQDestination> getDestinations() {
|
public Set<ActiveMQDestination> getDestinations() {
|
||||||
Set<ActiveMQDestination> results = new HashSet<ActiveMQDestination>();
|
Set<ActiveMQDestination> results = new HashSet<ActiveMQDestination>();
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
|
@ -212,6 +226,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long getLastMessageBrokerSequenceId() throws IOException {
|
public long getLastMessageBrokerSequenceId() throws IOException {
|
||||||
long maxId = -1;
|
long maxId = -1;
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
|
@ -220,6 +235,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
return maxId;
|
return maxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long getLastProducerSequenceId(ProducerId id) throws IOException {
|
public long getLastProducerSequenceId(ProducerId id) throws IOException {
|
||||||
long maxId = -1;
|
long maxId = -1;
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
|
@ -228,6 +244,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
return maxId;
|
return maxId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeQueueMessageStore(ActiveMQQueue destination) {
|
public void removeQueueMessageStore(ActiveMQQueue destination) {
|
||||||
PersistenceAdapter adapter = getMatchingPersistenceAdapter(destination);
|
PersistenceAdapter adapter = getMatchingPersistenceAdapter(destination);
|
||||||
adapter.removeQueueMessageStore(destination);
|
adapter.removeQueueMessageStore(destination);
|
||||||
|
@ -237,6 +254,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeTopicMessageStore(ActiveMQTopic destination) {
|
public void removeTopicMessageStore(ActiveMQTopic destination) {
|
||||||
PersistenceAdapter adapter = getMatchingPersistenceAdapter(destination);
|
PersistenceAdapter adapter = getMatchingPersistenceAdapter(destination);
|
||||||
if (adapter instanceof KahaDBPersistenceAdapter) {
|
if (adapter instanceof KahaDBPersistenceAdapter) {
|
||||||
|
@ -263,22 +281,26 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void rollbackTransaction(ConnectionContext context) throws IOException {
|
public void rollbackTransaction(ConnectionContext context) throws IOException {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setBrokerName(String brokerName) {
|
public void setBrokerName(String brokerName) {
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.setBrokerName(brokerName);
|
persistenceAdapter.setBrokerName(brokerName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setUsageManager(SystemUsage usageManager) {
|
public void setUsageManager(SystemUsage usageManager) {
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.setUsageManager(usageManager);
|
persistenceAdapter.setUsageManager(usageManager);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public long size() {
|
public long size() {
|
||||||
long size = 0;
|
long size = 0;
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
|
@ -287,6 +309,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void start() throws Exception {
|
public void start() throws Exception {
|
||||||
Object result = this.chooseValue(matchAll);
|
Object result = this.chooseValue(matchAll);
|
||||||
if (result != null) {
|
if (result != null) {
|
||||||
|
@ -373,12 +396,14 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
return adapter;
|
return adapter;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void stop() throws Exception {
|
public void stop() throws Exception {
|
||||||
for (PersistenceAdapter persistenceAdapter : adapters) {
|
for (PersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.stop();
|
persistenceAdapter.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public File getDirectory() {
|
public File getDirectory() {
|
||||||
return this.directory;
|
return this.directory;
|
||||||
}
|
}
|
||||||
|
@ -388,6 +413,7 @@ public class MultiKahaDBPersistenceAdapter extends DestinationMap implements Per
|
||||||
this.directory = directory;
|
this.directory = directory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void setBrokerService(BrokerService brokerService) {
|
public void setBrokerService(BrokerService brokerService) {
|
||||||
for (KahaDBPersistenceAdapter persistenceAdapter : adapters) {
|
for (KahaDBPersistenceAdapter persistenceAdapter : adapters) {
|
||||||
persistenceAdapter.setBrokerService(brokerService);
|
persistenceAdapter.setBrokerService(brokerService);
|
||||||
|
|
Loading…
Reference in New Issue