ARTEMIS-781 Add journal record for address binding

This commit is contained in:
jbertram 2016-10-10 15:11:50 -05:00 committed by Martyn Taylor
parent abdeb72eb7
commit 5e7475115d
7 changed files with 211 additions and 33 deletions

View File

@ -21,13 +21,13 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType; import org.apache.activemq.artemis.core.server.impl.AddressInfo;
public class CoreAddressConfiguration implements Serializable { public class CoreAddressConfiguration implements Serializable {
private String name = null; private String name = null;
private RoutingType routingType = null; private AddressInfo.RoutingType routingType = null;
private Integer defaultMaxConsumers = ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers(); private Integer defaultMaxConsumers = ActiveMQDefaultConfiguration.getDefaultMaxQueueConsumers();
@ -47,11 +47,11 @@ public class CoreAddressConfiguration implements Serializable {
return this; return this;
} }
public RoutingType getRoutingType() { public AddressInfo.RoutingType getRoutingType() {
return routingType; return routingType;
} }
public CoreAddressConfiguration setRoutingType(RoutingType routingType) { public CoreAddressConfiguration setRoutingType(AddressInfo.RoutingType routingType) {
this.routingType = routingType; this.routingType = routingType;
return this; return this;
} }

View File

@ -0,0 +1,34 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.core.persistence;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
public interface AddressBindingInfo {
long getId();
SimpleString getName();
boolean isAutoCreated();
SimpleString getUser();
AddressInfo.RoutingType getRoutingType();
}

View File

@ -0,0 +1,135 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.activemq.artemis.core.persistence.impl.journal.codec;
import org.apache.activemq.artemis.api.core.ActiveMQBuffer;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.core.journal.EncodingSupport;
import org.apache.activemq.artemis.core.persistence.AddressBindingInfo;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.utils.DataConstants;
public class PersistentAddressBindingEncoding implements EncodingSupport, AddressBindingInfo {
public long id;
public SimpleString name;
public boolean autoCreated;
public SimpleString user;
public AddressInfo.RoutingType routingType;
public PersistentAddressBindingEncoding() {
}
@Override
public String toString() {
return "PersistentAddressBindingEncoding [id=" + id +
", name=" +
name +
", user=" +
user +
", autoCreated=" +
autoCreated +
", routingType=" +
routingType +
"]";
}
public PersistentAddressBindingEncoding(final SimpleString name,
final SimpleString user,
final boolean autoCreated,
final AddressInfo.RoutingType routingType) {
this.name = name;
this.user = user;
this.autoCreated = autoCreated;
this.routingType = routingType;
}
@Override
public long getId() {
return id;
}
public void setId(final long id) {
this.id = id;
}
@Override
public SimpleString getName() {
return name;
}
@Override
public SimpleString getUser() {
return user;
}
@Override
public boolean isAutoCreated() {
return autoCreated;
}
@Override
public AddressInfo.RoutingType getRoutingType() {
return routingType;
}
@Override
public void decode(final ActiveMQBuffer buffer) {
name = buffer.readSimpleString();
String metadata = buffer.readNullableSimpleString().toString();
if (metadata != null) {
String[] elements = metadata.split(";");
for (String element : elements) {
String[] keyValuePair = element.split("=");
if (keyValuePair.length == 2) {
if (keyValuePair[0].equals("user")) {
user = SimpleString.toSimpleString(keyValuePair[1]);
}
}
}
}
autoCreated = buffer.readBoolean();
routingType = AddressInfo.RoutingType.getType(buffer.readByte());
}
@Override
public void encode(final ActiveMQBuffer buffer) {
buffer.writeSimpleString(name);
buffer.writeNullableSimpleString(createMetadata());
buffer.writeBoolean(autoCreated);
buffer.writeByte(routingType.getType());
}
@Override
public int getEncodeSize() {
return SimpleString.sizeofString(name) + DataConstants.SIZE_BOOLEAN +
SimpleString.sizeofNullableString(createMetadata()) +
DataConstants.SIZE_BYTE;
}
private SimpleString createMetadata() {
StringBuilder metadata = new StringBuilder();
metadata.append("user=").append(user).append(";");
return SimpleString.toSimpleString(metadata.toString());
}
}

View File

@ -16,18 +16,13 @@
*/ */
package org.apache.activemq.artemis.core.server.impl; package org.apache.activemq.artemis.core.server.impl;
import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.SimpleString;
public class AddressInfo { public class AddressInfo {
public enum RoutingType {
MULTICAST, ANYCAST
}
private final SimpleString name; private final SimpleString name;
private RoutingType routingType = RoutingType.MULTICAST; private RoutingType routingType = RoutingType.Multicast;
private boolean defaultDeleteOnNoConsumers; private boolean defaultDeleteOnNoConsumers;
@ -64,4 +59,30 @@ public class AddressInfo {
public SimpleString getName() { public SimpleString getName() {
return name; return name;
} }
public enum RoutingType {
Multicast, Anycast;
public byte getType() {
switch (this) {
case Multicast:
return 0;
case Anycast:
return 1;
default:
return -1;
}
}
public static RoutingType getType(byte type) {
switch (type) {
case 0:
return Multicast;
case 1:
return Anycast;
default:
return null;
}
}
}
} }

View File

@ -52,9 +52,6 @@ import org.apache.activemq.artemis.core.settings.impl.SlowConsumerPolicy;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import static org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType.ANYCAST;
import static org.apache.activemq.artemis.core.server.impl.AddressInfo.RoutingType.MULTICAST;
public class FileConfigurationTest extends ConfigurationImplTest { public class FileConfigurationTest extends ConfigurationImplTest {
private final String fullConfigurationName = "ConfigurationTest-full-config.xml"; private final String fullConfigurationName = "ConfigurationTest-full-config.xml";
@ -379,7 +376,7 @@ public class FileConfigurationTest extends ConfigurationImplTest {
// Addr 1 // Addr 1
CoreAddressConfiguration addressConfiguration = conf.getAddressConfigurations().get(0); CoreAddressConfiguration addressConfiguration = conf.getAddressConfigurations().get(0);
assertEquals("addr1", addressConfiguration.getName()); assertEquals("addr1", addressConfiguration.getName());
assertEquals(ANYCAST, addressConfiguration.getRoutingType()); assertEquals(AddressInfo.RoutingType.Anycast, addressConfiguration.getRoutingType());
assertEquals(2, addressConfiguration.getQueueConfigurations().size()); assertEquals(2, addressConfiguration.getQueueConfigurations().size());
// Addr 1 Queue 1 // Addr 1 Queue 1
@ -405,7 +402,7 @@ public class FileConfigurationTest extends ConfigurationImplTest {
// Addr 2 // Addr 2
addressConfiguration = conf.getAddressConfigurations().get(1); addressConfiguration = conf.getAddressConfigurations().get(1);
assertEquals("addr2", addressConfiguration.getName()); assertEquals("addr2", addressConfiguration.getName());
assertEquals(MULTICAST, addressConfiguration.getRoutingType()); assertEquals(AddressInfo.RoutingType.Multicast, addressConfiguration.getRoutingType());
assertEquals(2, addressConfiguration.getQueueConfigurations().size()); assertEquals(2, addressConfiguration.getQueueConfigurations().size());
// Addr 2 Queue 1 // Addr 2 Queue 1

View File

@ -50,19 +50,16 @@ public class XMLConfigurationMigration {
if (args.length == 0) { if (args.length == 0) {
System.err.println("Invalid args"); System.err.println("Invalid args");
printUsage(); printUsage();
} } else {
else {
File input = new File(args[0]); File input = new File(args[0]);
if (input.isDirectory()) { if (input.isDirectory()) {
System.out.println("Scanning directory: " + input.getAbsolutePath()); System.out.println("Scanning directory: " + input.getAbsolutePath());
recursiveTransform(input); recursiveTransform(input);
} } else {
else {
if (args.length != 2) { if (args.length != 2) {
System.err.println("Invalid args"); System.err.println("Invalid args");
printUsage(); printUsage();
} } else {
else {
transform(input, new File(args[1])); transform(input, new File(args[1]));
} }
} }
@ -70,13 +67,11 @@ public class XMLConfigurationMigration {
} }
private static void recursiveTransform(File root) throws Exception { private static void recursiveTransform(File root) throws Exception {
for ( File file : root.listFiles()) for (File file : root.listFiles()) {
{
scanAndTransform(file); scanAndTransform(file);
} }
} }
public static void scanAndTransform(File pFile) throws Exception { public static void scanAndTransform(File pFile) throws Exception {
try { try {
for (File f : pFile.listFiles()) { for (File f : pFile.listFiles()) {
@ -93,14 +88,12 @@ public class XMLConfigurationMigration {
file.renameTo(r); file.renameTo(r);
} }
} }
} } catch (Exception e) {
catch (Exception e) {
//continue //continue
} }
} }
} }
} } catch (NullPointerException e) {
catch (NullPointerException e) {
System.out.println(pFile.getAbsoluteFile()); System.out.println(pFile.getAbsoluteFile());
} }
} }
@ -125,9 +118,7 @@ public class XMLConfigurationMigration {
migration.write(output, properties); migration.write(output, properties);
return true; return true;
} }
} } catch (Exception e) {
catch (Exception e)
{
System.err.println("Error tranforming document"); System.err.println("Error tranforming document");
e.printStackTrace(); e.printStackTrace();
} }
@ -174,8 +165,7 @@ public class XMLConfigurationMigration {
if (addresses.containsKey(addressName)) { if (addresses.containsKey(addressName)) {
address = addresses.get(addressName); address = addresses.get(addressName);
} } else {
else {
address = new Address(); address = new Address();
address.setName(addressName); address.setName(addressName);
addresses.put(addressName, address); addresses.put(addressName, address);

View File

@ -1269,6 +1269,7 @@
<exclude>docs/**/_book/</exclude> <exclude>docs/**/_book/</exclude>
<exclude>**/target/</exclude> <exclude>**/target/</exclude>
<exclude>**/META-INF/services/*</exclude> <exclude>**/META-INF/services/*</exclude>
<exclude>**/META-INF/MANIFEST.MF</exclude>
<exclude>**/*.iml</exclude> <exclude>**/*.iml</exclude>
<exclude>**/*.jceks</exclude> <exclude>**/*.jceks</exclude>
<exclude>**/*.jks</exclude> <exclude>**/*.jks</exclude>