Skip to content

Commit

Permalink
WFLY-9613 Reduce lambda usage in clustering api externalizers/formats
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Jan 19, 2018
1 parent 45ff988 commit a1748af
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 33 deletions.
Expand Up @@ -22,33 +22,39 @@

package org.wildfly.clustering.server.group;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.function.Function;

import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.infinispan.spi.persistence.KeyFormat;
import org.wildfly.clustering.infinispan.spi.persistence.SimpleKeyFormat;
import org.wildfly.clustering.marshalling.Externalizer;
import org.wildfly.clustering.marshalling.spi.StringExternalizer;

/**
* Marshalling externalizer for a {@link LocalNode}.
* Resolver for a {@link LocalNode}.
* @author Paul Ferraro
*/
@MetaInfServices({ Externalizer.class, KeyFormat.class })
public class LocalNodeExternalizer extends SimpleKeyFormat<LocalNode> implements Externalizer<LocalNode> {
public enum LocalNodeResolver implements Function<String, LocalNode> {
INSTANCE;

public LocalNodeExternalizer() {
super(LocalNode.class, LocalNode::new, LocalNode::getName);
@Override
public LocalNode apply(String name) {
return new LocalNode(name);
}

@Override
public void writeObject(ObjectOutput output, LocalNode node) throws IOException {
output.writeUTF(node.getName());
static final Function<LocalNode, String> PARSER = LocalNode::getName;

@MetaInfServices(Externalizer.class)
public static class LocalNodeExternalizer extends StringExternalizer<LocalNode> {
public LocalNodeExternalizer() {
super(LocalNode.class, INSTANCE, PARSER);
}
}

@Override
public LocalNode readObject(ObjectInput input) throws IOException {
return new LocalNode(input.readUTF());
@MetaInfServices(KeyFormat.class)
public static class LocalNodeKeyFormat extends SimpleKeyFormat<LocalNode> {
public LocalNodeKeyFormat() {
super(LocalNode.class, INSTANCE, PARSER);
}
}
}
Expand Up @@ -21,34 +21,40 @@
*/
package org.wildfly.clustering.server.singleton;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.util.function.Function;

import org.jboss.msc.service.ServiceName;
import org.kohsuke.MetaInfServices;
import org.wildfly.clustering.infinispan.spi.persistence.KeyFormat;
import org.wildfly.clustering.infinispan.spi.persistence.SimpleKeyFormat;
import org.wildfly.clustering.marshalling.Externalizer;
import org.wildfly.clustering.marshalling.spi.StringExternalizer;

/**
* {@link Externalizer} for a {@link ServiceName}.
* @author Paul Ferraro
*/
@MetaInfServices({ Externalizer.class, KeyFormat.class })
public class ServiceNameExternalizer extends SimpleKeyFormat<ServiceName> implements Externalizer<ServiceName> {
public enum ServiceNameResolver implements Function<String, ServiceName> {
RESOLVER;

public ServiceNameExternalizer() {
super(ServiceName.class, ServiceName::parse, ServiceName::getCanonicalName);
@Override
public ServiceName apply(String name) {
return ServiceName.parse(name);
}

@Override
public void writeObject(ObjectOutput output, ServiceName name) throws IOException {
output.writeUTF(name.getCanonicalName());
static final Function<ServiceName, String> PARSER = ServiceName::getCanonicalName;

@MetaInfServices(Externalizer.class)
public static class ServiceNameExternalizer extends StringExternalizer<ServiceName> {
public ServiceNameExternalizer() {
super(ServiceName.class, RESOLVER, PARSER);
}
}

@Override
public ServiceName readObject(ObjectInput input) throws IOException {
return ServiceName.parse(input.readUTF());
@MetaInfServices(KeyFormat.class)
public static class ServiceNameKeyFormat extends SimpleKeyFormat<ServiceName> {
public ServiceNameKeyFormat() {
super(ServiceName.class, RESOLVER, PARSER);
}
}
}
Expand Up @@ -25,16 +25,22 @@
import java.io.IOException;

import org.junit.Test;
import org.wildfly.clustering.infinispan.spi.persistence.KeyFormatTester;
import org.wildfly.clustering.marshalling.ExternalizerTester;
import org.wildfly.clustering.server.group.LocalNodeResolver.LocalNodeExternalizer;
import org.wildfly.clustering.server.group.LocalNodeResolver.LocalNodeKeyFormat;

/**
* Unit test for {@link LocalNodeExternalizer}.
* Unit test for {@link LocalNodeResolver}.
* @author Paul Ferraro
*/
public class LocalNodeExternalizerTestCase {
public class LocalNodeResolverTestCase {

@Test
public void test() throws ClassNotFoundException, IOException {
new ExternalizerTester<>(new LocalNodeExternalizer()).test(new LocalNode("name"));
LocalNode node = new LocalNode("name");

new ExternalizerTester<>(new LocalNodeExternalizer()).test(node);
new KeyFormatTester<>(new LocalNodeKeyFormat()).test(node);
}
}
Expand Up @@ -26,16 +26,22 @@

import org.jboss.msc.service.ServiceName;
import org.junit.Test;
import org.wildfly.clustering.infinispan.spi.persistence.KeyFormatTester;
import org.wildfly.clustering.marshalling.ExternalizerTester;
import org.wildfly.clustering.server.singleton.ServiceNameResolver.ServiceNameExternalizer;
import org.wildfly.clustering.server.singleton.ServiceNameResolver.ServiceNameKeyFormat;

/**
* Unit test for {@link ServiceNameExternalizer}.
* Unit test for {@link ServiceNameResolver}.
* @author Paul Ferraro
*/
public class ServiceNameExternalizerTestCase {
public class ServiceNameResolverTestCase {

@Test
public void test() throws ClassNotFoundException, IOException {
new ExternalizerTester<>(new ServiceNameExternalizer()).test(ServiceName.JBOSS.append("service"));
ServiceName name = ServiceName.JBOSS.append("service");

new ExternalizerTester<>(new ServiceNameExternalizer()).test(name);
new KeyFormatTester<>(new ServiceNameKeyFormat()).test(name);
}
}

0 comments on commit a1748af

Please sign in to comment.