From 05f4af53fd9442653ccda8d5319a2e9fabc82341 Mon Sep 17 00:00:00 2001 From: Rob Austin Date: Thu, 12 Mar 2015 14:50:17 +0000 Subject: [PATCH] CE-14 abstracted out client and server sides of engine --- .../chronicle/map/ChannelProvider.java | 6 +- .../net/openhft/chronicle/map/Replica.java | 2 +- .../chronicle/map/ServiceDescriptor.java | 80 +++++++++++++++++++ 3 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 src/main/java/net/openhft/chronicle/map/ServiceDescriptor.java diff --git a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java index a6efc7525..47e1f549f 100644 --- a/src/main/java/net/openhft/chronicle/map/ChannelProvider.java +++ b/src/main/java/net/openhft/chronicle/map/ChannelProvider.java @@ -49,12 +49,12 @@ import static net.openhft.chronicle.map.Replica.ModificationNotifier.NOP; /** * @author Rob Austin. */ -final class ChannelProvider implements Closeable { +public final class ChannelProvider implements Closeable { private static final Logger LOG = LoggerFactory.getLogger(ChannelProvider.class.getName()); static final Map implMapping = new IdentityHashMap<>(); - static synchronized ChannelProvider getProvider(ReplicationHub hub ) throws IOException { + public static synchronized ChannelProvider getProvider(ReplicationHub hub ) throws IOException { ChannelProvider channelProvider = implMapping.get(hub); if (channelProvider != null) return channelProvider; @@ -269,7 +269,7 @@ final class ChannelProvider implements Closeable { private final Replica[] chronicleChannels; - List chronicleChannelList() { + public List chronicleChannelList() { return Collections.unmodifiableList(chronicleChannelList); } diff --git a/src/main/java/net/openhft/chronicle/map/Replica.java b/src/main/java/net/openhft/chronicle/map/Replica.java index c3643fd4d..7f54abc69 100644 --- a/src/main/java/net/openhft/chronicle/map/Replica.java +++ b/src/main/java/net/openhft/chronicle/map/Replica.java @@ -26,7 +26,7 @@ import java.io.Closeable; /** * @author Rob Austin. */ -interface Replica extends Closeable { +public interface Replica extends Closeable { /** * Provides the unique Identifier associated with this map instance.

An identifier is used diff --git a/src/main/java/net/openhft/chronicle/map/ServiceDescriptor.java b/src/main/java/net/openhft/chronicle/map/ServiceDescriptor.java new file mode 100644 index 000000000..aa82953e1 --- /dev/null +++ b/src/main/java/net/openhft/chronicle/map/ServiceDescriptor.java @@ -0,0 +1,80 @@ +/* + * Copyright 2014 Higher Frequency Trading + * + * http://www.higherfrequencytrading.com + * + * Licensed 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 net.openhft.chronicle.map; + +import net.openhft.chronicle.wire.Marshallable; +import net.openhft.chronicle.wire.WireIn; +import net.openhft.chronicle.wire.WireOut; + +public class ServiceDescriptor implements Marshallable { + + public Class keyClass; + public Class valueClass; + public short channelID; + + public ServiceDescriptor() { + } + + public ServiceDescriptor(Class keyClass, Class valueClass, short channelID) { + this.keyClass = keyClass; + this.valueClass = valueClass; + this.channelID = channelID; + } + + + @Override + public void writeMarshallable(WireOut wire) { + wire.write(() -> "keyClass").text(keyClass.getName()); + wire.write(() -> "valueClass").text(valueClass.getName()); + wire.write(() -> "channelID").int16(channelID); + } + + @Override + public void readMarshallable(WireIn wire) throws IllegalStateException { + try { + keyClass = (Class) Class.forName(wire.read(() -> "keyClass").text()); + valueClass = (Class) Class.forName(wire.read(() -> "valueClass").text()); + channelID = wire.read(() -> "channelID").int16(); + } catch (ClassNotFoundException e) { + throw new RuntimeException(e); + } + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ServiceDescriptor serviceDescriptor = (ServiceDescriptor) o; + + if (channelID != serviceDescriptor.channelID) return false; + if (!keyClass.equals(serviceDescriptor.keyClass)) return false; + if (!valueClass.equals(serviceDescriptor.valueClass)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = keyClass.hashCode(); + result = 31 * result + valueClass.hashCode(); + result = 31 * result + (int) channelID; + return result; + } + } \ No newline at end of file