You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ud...@apache.org on 2016/02/22 22:43:27 UTC
[039/100] [abbrv] [partial] incubator-geode git commit: Merge
remote-tracking branch 'origin/develop' into feature/GEODE-917
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
index 419c096,0000000..c958028
mode 100644,000000..100644
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/LonerDistributionManager.java
@@@ -1,997 -1,0 +1,1001 @@@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal;
+
+import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+import java.util.Vector;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import com.gemstone.gemfire.CancelCriterion;
+import com.gemstone.gemfire.InternalGemFireError;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.distributed.DurableClientAttributes;
+import com.gemstone.gemfire.distributed.Role;
+import com.gemstone.gemfire.distributed.internal.locks.ElderState;
+import com.gemstone.gemfire.distributed.internal.membership.InternalDistributedMember;
+import com.gemstone.gemfire.distributed.internal.membership.MemberAttributes;
+import com.gemstone.gemfire.distributed.internal.membership.MembershipManager;
+import com.gemstone.gemfire.i18n.LogWriterI18n;
+import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.Version;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+import com.gemstone.gemfire.internal.logging.InternalLogWriter;
+
+/**
+ * A <code>LonerDistributionManager</code> is a dm that never communicates
+ * with anyone else.
+ *
+ * @author Darrel
+ *
+ *
+ * @since 3.5
+ */
+public class LonerDistributionManager implements DM {
+ private final InternalDistributedSystem system;
+ private final InternalLogWriter logger;
+ private ElderState elderState;
+
+
+ //////////////////////// Constructors ////////////////////////
+
+ /**
+ * Creates a new local distribution manager
+ *
+ * @param system
+ * The distributed system to which this distribution manager
+ * will send messages.
+ *
+ */
+ public LonerDistributionManager(InternalDistributedSystem system,
+ InternalLogWriter logger) {
+ this.system = system;
+ this.logger = logger;
+ this.id = generateMemberId();
+ this.allIds = Collections.singleton(id);
+ this.viewMembers = new ArrayList<InternalDistributedMember>(allIds);
+ DistributionStats.enableClockStats = this.system.getConfig().getEnableTimeStatistics();
+ }
+
+ ////////////////////// Instance Methods //////////////////////
+
+ protected void startThreads() {
+ // no threads needed
+ }
+
+ protected void shutdown() {
+ }
+
+ private final InternalDistributedMember id;
+
+ /*static {
+ // Make the id a little unique
+ String host;
+ try {
+ host = InetAddress.getLocalHost().getCanonicalHostName();
+ MemberAttributes.setDefaults(65535,
+ com.gemstone.gemfire.internal.OSProcess.getId(),
+ DistributionManager.LONER_DM_TYPE,
+ MemberAttributes.parseRoles(system.getConfig().getRoles()));
+ id = new InternalDistributedMember(host, 65535); // noise value for port number
+
+ } catch (UnknownHostException ex) {
+ throw new InternalError(LocalizedStrings.LonerDistributionManager_CANNOT_RESOLVE_LOCAL_HOST_NAME_TO_AN_IP_ADDRESS.toLocalizedString());
+ }
+
+ }*/
+
+ private final Set<InternalDistributedMember> allIds;// = Collections.singleton(id);
+ private final List<InternalDistributedMember> viewMembers;
+ private ConcurrentMap<InternalDistributedMember, InternalDistributedMember> canonicalIds = new ConcurrentHashMap();
+ static private final DummyDMStats stats = new DummyDMStats();
+ static private final DummyExecutor executor = new DummyExecutor();
+
+ @Override
+ public long cacheTimeMillis() {
+ return this.system.getClock().cacheTimeMillis();
+ }
+ public InternalDistributedMember getDistributionManagerId() {
+ return id;
+ }
+
+ public Set getDistributionManagerIds() {
+ return allIds;
+ }
+
+ public Set getDistributionManagerIdsIncludingAdmin() {
+ return allIds;
+ }
+ public Serializable[] getDirectChannels(InternalDistributedMember[] ids) {
+ return ids;
+ }
+
+ public InternalDistributedMember getCanonicalId(DistributedMember dmid) {
+ InternalDistributedMember iid = (InternalDistributedMember)dmid;
+ InternalDistributedMember result = this.canonicalIds.putIfAbsent(iid,iid);
+ if (result != null) {
+ return result;
+ }
+ return iid;
+ }
+
+ public Set getOtherDistributionManagerIds() {
+ return Collections.EMPTY_SET;
+ }
+ @Override
+ public Set getOtherNormalDistributionManagerIds() {
+ return Collections.EMPTY_SET;
+ }
+ public Set getAllOtherMembers() {
+ return Collections.EMPTY_SET;
+ }
+
+ @Override // DM method
+ public void retainMembersWithSameOrNewerVersion(Collection<InternalDistributedMember> members, Version version) {
+ for (Iterator<InternalDistributedMember> it = members.iterator(); it.hasNext(); ) {
+ InternalDistributedMember id = it.next();
+ if (id.getVersionObject().compareTo(version) < 0) {
+ it.remove();
+ }
+ }
+ }
+
+ @Override // DM method
+ public void removeMembersWithSameOrNewerVersion(Collection<InternalDistributedMember> members, Version version) {
+ for (Iterator<InternalDistributedMember> it = members.iterator(); it.hasNext(); ) {
+ InternalDistributedMember id = it.next();
+ if (id.getVersionObject().compareTo(version) >= 0) {
+ it.remove();
+ }
+ }
+ }
+
+
+ public Set addMembershipListenerAndGetDistributionManagerIds(MembershipListener l) {
+ //return getOtherDistributionManagerIds();
+ return allIds;
+ }
+ public Set addAllMembershipListenerAndGetAllIds(MembershipListener l) {
+ return allIds;
+ }
+ public int getDistributionManagerCount() {
+ return 0;
+ }
+ public InternalDistributedMember getId() {
+ return getDistributionManagerId();
+ }
+ public boolean isAdam() {
+ return true;
+ }
+ public InternalDistributedMember getElderId() {
+ return getId();
+ }
+ public boolean isElder() {
+ return true;
+ }
+ public boolean isLoner() {
+ return true;
+ }
+
+ public synchronized ElderState getElderState(boolean force, boolean useTryLock) {
+ // loners are always the elder
+ if (this.elderState == null) {
+ this.elderState = new ElderState(this);
+ }
+ return this.elderState;
+ }
+
+ public long getChannelId() {
+ return 0;
+ }
+
+ public Set putOutgoingUserData(final DistributionMessage message) {
+ if (message.forAll() || message.getRecipients().length == 0) {
+ // do nothing
+ return null;
+ } else {
+ throw new RuntimeException(LocalizedStrings.LonerDistributionManager_LONER_TRIED_TO_SEND_MESSAGE_TO_0.toLocalizedString(message.getRecipientsDescription()));
+ }
+ }
+ public InternalDistributedSystem getSystem() {
+ return this.system;
+ }
+ public void addMembershipListener(MembershipListener l) {}
+
+ public void removeMembershipListener(MembershipListener l) {}
+ public void removeAllMembershipListener(MembershipListener l) {}
+
+ public void addAdminConsole(InternalDistributedMember p_id) {}
+
+ public DMStats getStats() {
+ return stats;
+ }
+ public DistributionConfig getConfig() {
+ DistributionConfig result = null;
+ if (getSystem() != null) {
+ result = getSystem().getConfig();
+ }
+ return result;
+ }
+
+ public void handleManagerDeparture(InternalDistributedMember p_id,
+ boolean crashed, String reason) {}
+
+ public LogWriterI18n getLoggerI18n() {
+ return this.logger;
+ }
+ public InternalLogWriter getInternalLogWriter() {
+ return this.logger;
+ }
+ public ExecutorService getThreadPool() {
+ return executor;
+ }
+ public ExecutorService getHighPriorityThreadPool() {
+ return executor;
+ }
+ public ExecutorService getWaitingThreadPool() {
+ return executor;
+ }
+ public ExecutorService getPrMetaDataCleanupThreadPool() {
+ return executor;
+ }
+ public Map getChannelMap() {
+ return null;
+ }
+ public Map getMemberMap() {
+ return null;
+ }
+ public void close() {
+ }
+ public void restartCommunications() {
+
+ }
+
+ @Override
+ public List<InternalDistributedMember> getViewMembers() {
+ return viewMembers;
+ }
+
+ public DistributedMember getOldestMember(Collection members) throws NoSuchElementException {
+ if (members.size() == 1) {
+ DistributedMember member = (DistributedMember)members.iterator().next();
+ if (member.equals(viewMembers.get(0))) {
+ return member;
+ }
+ }
+ throw new NoSuchElementException(LocalizedStrings.LonerDistributionManager_MEMBER_NOT_FOUND_IN_MEMBERSHIP_SET.toLocalizedString());
+ }
+
+ public Set getAdminMemberSet(){ return Collections.EMPTY_SET; }
+
+ public static class DummyDMStats implements DMStats {
+ @Override
+ public long getSentMessages() {return 0;}
+ @Override
+ public void incSentMessages(long messages) {}
+ @Override
+ public void incTOSentMsg() {}
+ @Override
+ public long getSentCommitMessages() {return 0;}
+ @Override
+ public void incSentCommitMessages(long messages) {}
+ @Override
+ public long getCommitWaits() {return 0;}
+ @Override
+ public void incCommitWaits() {}
+ @Override
+ public long getSentMessagesTime() {return 0;}
+ @Override
+ public void incSentMessagesTime(long nanos) {}
+ @Override
+ public long getBroadcastMessages() {return 0;}
+ @Override
+ public void incBroadcastMessages(long messages) {}
+ @Override
+ public long getBroadcastMessagesTime() {return 0;}
+ @Override
+ public void incBroadcastMessagesTime(long nanos) {}
+ @Override
+ public long getReceivedMessages() {return 0;}
+ @Override
+ public void incReceivedMessages(long messages) {}
+ @Override
+ public long getReceivedBytes() {return 0;}
+ @Override
+ public void incReceivedBytes(long bytes) {}
+ @Override
+ public void incSentBytes(long bytes) {}
+ @Override
+ public long getProcessedMessages() {return 0;}
+ @Override
+ public void incProcessedMessages(long messages) {}
+ @Override
+ public long getProcessedMessagesTime() {return 0;}
+ @Override
+ public void incProcessedMessagesTime(long nanos) {}
+ @Override
+ public long getMessageProcessingScheduleTime() {return 0;}
+ @Override
+ public void incMessageProcessingScheduleTime(long nanos) {}
+ @Override
+ public int getOverflowQueueSize() {return 0;}
+ @Override
+ public void incOverflowQueueSize(int messages) {}
+ @Override
+ public int getNumProcessingThreads() {return 0;}
+ @Override
+ public void incNumProcessingThreads(int threads) {}
+ @Override
+ public int getNumSerialThreads() {return 0;}
+ @Override
+ public void incNumSerialThreads(int threads) {}
+ @Override
+ public void incMessageChannelTime(long val) {}
+ @Override
++ public void incUDPDispatchRequestTime(long val) {};
++ @Override
++ public long getUDPDispatchRequestTime() {return 0;};
++ @Override
+ public long getReplyMessageTime() {return 0;}
+ @Override
+ public void incReplyMessageTime(long val) {}
+ @Override
+ public long getDistributeMessageTime() {return 0;}
+ @Override
+ public void incDistributeMessageTime(long val) {}
+ @Override
+ public int getNodes() {return 0;}
+ @Override
+ public void setNodes(int val) {}
+ @Override
+ public void incNodes(int val) {}
+ @Override
+ public int getReplyWaitsInProgress() {return 0;}
+ @Override
+ public int getReplyWaitsCompleted() {return 0;}
+ @Override
+ public long getReplyWaitTime() {return 0;}
+ @Override
+ public long startReplyWait() {return 0;}
+ @Override
+ public void endReplyWait(long startNanos, long startMillis) {}
+ @Override
+ public void incReplyTimeouts() { }
+ @Override
+ public long getReplyTimeouts() { return 0; }
+ @Override
+ public void incReceivers() {}
+ @Override
+ public void decReceivers() {}
+ @Override
+ public void incFailedAccept() {}
+ @Override
+ public void incFailedConnect() {}
+ @Override
+ public void incReconnectAttempts() {}
+ @Override
+ public void incLostLease() {}
+ @Override
+ public void incSenders(boolean shared, boolean preserveOrder) {}
+ @Override
+ public void decSenders(boolean shared, boolean preserveOrder) {}
+ @Override
+ public int getSendersSU() { return 0; }
+ @Override
+ public long startSocketWrite(boolean sync) {return 0; }
+ @Override
+ public void endSocketWrite(boolean sync, long start, int bytesWritten, int retries) {}
+ @Override
+ public long startSerialization() {return 0;}
+ @Override
+ public void endSerialization(long start, int bytes) {}
+ @Override
+ public long startDeserialization() {return 0;}
+ @Override
+ public void endDeserialization(long start, int bytes) {}
+ @Override
+ public long startMsgSerialization() {return 0;}
+ @Override
+ public void endMsgSerialization(long start) {}
+ @Override
+ public long startMsgDeserialization() {return 0;}
+ @Override
+ public void endMsgDeserialization(long start) {}
+ @Override
+ public void incBatchSendTime(long start) {}
+ @Override
+ public void incBatchCopyTime(long start) {}
+ @Override
+ public void incBatchWaitTime(long start) {}
+ @Override
+ public void incBatchFlushTime(long start) {}
+ @Override
+ public void incUcastWriteBytes(int bytesWritten) {}
+ @Override
+ public void incMcastWriteBytes(int bytesWritten) {}
+ @Override
+ public void incUcastRetransmits() {}
+ @Override
+ public void incMcastRetransmits() {}
+ @Override
+ public void incMcastRetransmitRequests() {}
+ @Override
+ public int getMcastRetransmits() { return 0; }
+ @Override
+ public int getMcastWrites() { return 0; }
+ @Override
+ public int getMcastReads() { return 0; }
+ @Override
+ public void incUcastReadBytes(int amount) {}
+ @Override
+ public void incMcastReadBytes(int amount) {}
+ @Override
+ public int getAsyncSocketWritesInProgress() {return 0;}
+ @Override
+ public int getAsyncSocketWrites() {return 0;}
+ @Override
+ public int getAsyncSocketWriteRetries() {return 0;}
+ @Override
+ public long getAsyncSocketWriteBytes() {return 0;}
+ @Override
+ public long getAsyncSocketWriteTime() {return 0;}
+ @Override
+ public int getAsyncQueues() {return 0;}
+ @Override
+ public void incAsyncQueues(int inc) {}
+ @Override
+ public int getAsyncQueueFlushesInProgress() {return 0;}
+ @Override
+ public int getAsyncQueueFlushesCompleted() {return 0;}
+ @Override
+ public long getAsyncQueueFlushTime() {return 0;}
+ @Override
+ public long startAsyncQueueFlush() {return 0;}
+ @Override
+ public void endAsyncQueueFlush(long start) {}
+ @Override
+ public int getAsyncQueueTimeouts() {return 0;}
+ @Override
+ public void incAsyncQueueTimeouts(int inc) {}
+ @Override
+ public int getAsyncQueueSizeExceeded() {return 0;}
+ @Override
+ public void incAsyncQueueSizeExceeded(int inc) {}
+ @Override
+ public int getAsyncDistributionTimeoutExceeded() {return 0;}
+ @Override
+ public void incAsyncDistributionTimeoutExceeded() {}
+ @Override
+ public long getAsyncQueueSize() {return 0;}
+ @Override
+ public void incAsyncQueueSize(long inc) {}
+ @Override
+ public long getAsyncQueuedMsgs() {return 0;}
+ @Override
+ public void incAsyncQueuedMsgs() {}
+ @Override
+ public long getAsyncDequeuedMsgs() {return 0;}
+ @Override
+ public void incAsyncDequeuedMsgs() {}
+ @Override
+ public long getAsyncConflatedMsgs() {return 0;}
+ @Override
+ public void incAsyncConflatedMsgs() {}
+ @Override
+ public int getAsyncThreads() {return 0;}
+ @Override
+ public void incAsyncThreads(int inc) {}
+ @Override
+ public int getAsyncThreadInProgress() {return 0;}
+ @Override
+ public int getAsyncThreadCompleted() {return 0;}
+ @Override
+ public long getAsyncThreadTime() {return 0;}
+ @Override
+ public long startAsyncThread() {return 0;}
+ @Override
+ public void endAsyncThread(long start) {}
+ @Override
+ public long getAsyncQueueAddTime() {return 0;}
+ @Override
+ public void incAsyncQueueAddTime(long inc) {}
+ @Override
+ public long getAsyncQueueRemoveTime() {return 0;}
+ @Override
+ public void incAsyncQueueRemoveTime(long inc) {}
+ @Override
+ public void incReceiverBufferSize(int inc, boolean direct) {}
+ @Override
+ public void incSenderBufferSize(int inc, boolean direct) {}
+ @Override
+ public long startSocketLock() {return 0;}
+ @Override
+ public void endSocketLock(long start) {}
+ @Override
+ public long startBufferAcquire() {return 0;}
+ @Override
+ public void endBufferAcquire(long start) {}
+ @Override
+ public void incMessagesBeingReceived(boolean newMsg, int bytes) {}
+ @Override
+ public void decMessagesBeingReceived(int bytes) {}
+ @Override
+ public void incReplyHandOffTime(long start) {}
+ @Override
+ public int getElders() {return 0;}
+ @Override
+ public void incElders(int val) {}
+ @Override
+ public int getInitialImageMessagesInFlight() {return 0;}
+ @Override
+ public void incInitialImageMessagesInFlight(int val) {}
+ @Override
+ public int getInitialImageRequestsInProgress() {return 0;}
+ @Override
+ public void incInitialImageRequestsInProgress(int val) {}
+ @Override
+ public void incPdxSerialization(int bytesWritten) {}
+ @Override
+ public void incPdxDeserialization(int i) {}
+ @Override
+ public long startPdxInstanceDeserialization() {return 0;}
+ @Override
+ public void endPdxInstanceDeserialization(long start) {}
+ @Override
+ public void incPdxInstanceCreations() {}
+ @Override
+ public void incThreadOwnedReceivers(long value, int dominoCount) {
+ }
+ @Override
+ public long getHeartbeatRequestsSent() {return 0;}
+ @Override
+ public void incHeartbeatRequestsSent() {}
+ @Override
+ public long getHeartbeatRequestsReceived() {return 0;}
+ @Override
+ public void incHeartbeatRequestsReceived() {}
+ @Override
+ public long getHeartbeatsSent() {return 0;}
+ @Override
+ public void incHeartbeatsSent() {}
+ @Override
+ public long getHeartbeatsReceived() {return 0;}
+ @Override
+ public void incHeartbeatsReceived() {}
+ @Override
+ public long getSuspectsSent() {return 0;}
+ @Override
+ public void incSuspectsSent() {}
+ @Override
+ public long getSuspectsReceived() {return 0;}
+ @Override
+ public void incSuspectsReceived() {}
+ @Override
+ public long getFinalCheckRequestsSent() {return 0;}
+ @Override
+ public void incFinalCheckRequestsSent() {}
+ @Override
+ public long getFinalCheckRequestsReceived() {return 0;}
+ @Override
+ public void incFinalCheckRequestsReceived() {}
+ @Override
+ public long getFinalCheckResponsesSent() {return 0;}
+ @Override
+ public void incFinalCheckResponsesSent() {}
+ @Override
+ public long getFinalCheckResponsesReceived() {return 0;}
+ @Override
+ public void incFinalCheckResponsesReceived() {}
+ @Override
+ public long getTcpFinalCheckRequestsSent() {return 0;}
+ @Override
+ public void incTcpFinalCheckRequestsSent() {}
+ @Override
+ public long getTcpFinalCheckRequestsReceived() {return 0;}
+ @Override
+ public void incTcpFinalCheckRequestsReceived() {}
+ @Override
+ public long getTcpFinalCheckResponsesSent() {return 0;}
+ @Override
+ public void incTcpFinalCheckResponsesSent() {}
+ @Override
+ public long getTcpFinalCheckResponsesReceived() {return 0;}
+ @Override
+ public void incTcpFinalCheckResponsesReceived() {}
+ @Override
+ public long getUdpFinalCheckRequestsSent() {return 0;}
+ @Override
+ public void incUdpFinalCheckRequestsSent() {}
+ @Override
+ public long getUdpFinalCheckResponsesReceived() {return 0;}
+ @Override
+ public void incUdpFinalCheckResponsesReceived() {}
+ }
+ protected static class DummyExecutor implements ExecutorService {
+ @Override
+ public void execute(Runnable command) {
+ command.run();
+ }
+
+ @Override
+ public void shutdown() {
+ }
+
+ @Override
+ public List<Runnable> shutdownNow() {
+ return Collections.emptyList();
+ }
+
+ @Override
+ public boolean isShutdown() {
+ return false;
+ }
+
+ @Override
+ public boolean isTerminated() {
+ return false;
+ }
+
+ @Override
+ public boolean awaitTermination(long timeout, TimeUnit unit)
+ throws InterruptedException {
+ return true;
+ }
+
+ @Override
+ public <T> Future<T> submit(final Callable<T> task) {
+ Exception ex = null;
+ T result = null;
+ try {
+ result = task.call();
+ } catch (Exception e) {
+ ex = e;
+ }
+ return new CompletedFuture<T>(result, ex);
+ }
+
+ @Override
+ public <T> Future<T> submit(final Runnable task, final T result) {
+ return submit(new Callable<T>() {
+ @Override
+ public T call() throws Exception {
+ task.run();
+ return result;
+ }
+ });
+ }
+
+ @Override
+ public Future<?> submit(Runnable task) {
+ return submit(task, null);
+ }
+
+ @Override
+ public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks)
+ throws InterruptedException {
+ List<Future<T>> results = new ArrayList<Future<T>>();
+ for (Callable<T> task : tasks) {
+ results.add(submit(task));
+ }
+ return results;
+ }
+
+ @Override
+ public <T> List<Future<T>> invokeAll(
+ Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
+ throws InterruptedException {
+ return invokeAll(tasks);
+ }
+
+ @Override
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
+ throws InterruptedException, ExecutionException {
+
+ ExecutionException ex = null;
+ for (Callable<T> task : tasks) {
+ try {
+ return submit(task).get();
+ } catch (ExecutionException e) {
+ ex = e;
+ }
+ }
+ throw (ExecutionException) ex.fillInStackTrace();
+ }
+
+ @Override
+ public <T> T invokeAny(Collection<? extends Callable<T>> tasks,
+ long timeout, TimeUnit unit) throws InterruptedException,
+ ExecutionException, TimeoutException {
+ return invokeAny(tasks);
+ }
+ }
+
+ private static class CompletedFuture<T> implements Future<T> {
+ private final T result;
+ private final Exception ex;
+
+ public CompletedFuture(T result, Exception ex) {
+ this.result = result;
+ this.ex = ex;
+ }
+
+ @Override
+ public boolean cancel(boolean mayInterruptIfRunning) {
+ return false;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return false;
+ }
+
+ @Override
+ public boolean isDone() {
+ return true;
+ }
+
+ @Override
+ public T get() throws InterruptedException, ExecutionException {
+ if (ex != null) {
+ throw new ExecutionException(ex);
+ }
+ return result;
+ }
+
+ @Override
+ public T get(long timeout, TimeUnit unit) throws InterruptedException,
+ ExecutionException, TimeoutException {
+ return get();
+ }
+ }
+
+ public void throwIfDistributionStopped() {
+ stopper.checkCancelInProgress(null);
+ }
+
+ /** Returns count of members filling the specified role */
+ public int getRoleCount(Role role) {
+ return id.getRoles().contains(role) ? 1 : 0;
+ }
+
+ /** Returns true if at least one member is filling the specified role */
+ public boolean isRolePresent(Role role) {
+ return id.getRoles().contains(role);
+ }
+
+ /** Returns a set of all roles currently in the distributed system. */
+ public Set getAllRoles() {
+ return id.getRoles();
+ }
+
+ private int lonerPort = 0;
+
+ //private static final int CHARS_32KB = 16384;
+ private InternalDistributedMember generateMemberId() {
+ InternalDistributedMember result = null;
+ String host;
+ try {
+ // create string of the current millisecond clock time
+ StringBuffer sb = new StringBuffer();
+ // use low four bytes for backward compatibility
+ long time = System.currentTimeMillis() & 0xffffffffL;
+ for (int i = 0; i < 4; i++) {
+ String hex = Integer.toHexString((int)(time & 0xff));
+ if (hex.length() < 2) {
+ sb.append('0');
+ }
+ sb.append(hex);
+ time = time / 0x100;
+ }
+ String uniqueString = sb.toString();
+
+ String name = this.system.getName();
+
+ host = SocketCreator.getLocalHost().getCanonicalHostName();
+ DistributionConfig config = system.getConfig();
+ DurableClientAttributes dac = null;
+ if (config.getDurableClientId() != null) {
+ dac = new DurableClientAttributes(config.getDurableClientId(), config
+ .getDurableClientTimeout());
+ }
+ result = new InternalDistributedMember(host, lonerPort, name, uniqueString, DistributionManager.LONER_DM_TYPE,
+ MemberAttributes.parseGroups(config.getRoles(), config.getGroups()), dac);
+
+ } catch (UnknownHostException ex) {
+ throw new InternalGemFireError(LocalizedStrings.LonerDistributionManager_CANNOT_RESOLVE_LOCAL_HOST_NAME_TO_AN_IP_ADDRESS.toLocalizedString());
+ }
+ return result;
+ }
+
+ /**
+ * update the loner port with an integer that may be more unique than the
+ * default port (zero). This updates the ID in place and establishes new
+ * default settings for the manufacture of new IDs.
+ *
+ * @param newPort the new port to use
+ */
+ public void updateLonerPort(int newPort) {
+ this.lonerPort = newPort;
+ this.getId().setPort(this.lonerPort);
+ this.logger.config(LocalizedStrings.LonerDistributionmanager_CHANGING_PORT_FROM_TO,
+ new Object[]{this.lonerPort, newPort, getId()});
+ }
+ public boolean isCurrentMember(InternalDistributedMember p_id) {
+ return getId().equals(p_id);
+ }
+
+ public Set putOutgoing(DistributionMessage msg)
+ {
+ return null;
+ }
+
+ public boolean shutdownInProgress() {
+ return false;
+ }
+
+ public void removeUnfinishedStartup(InternalDistributedMember m, boolean departed) {
+ }
+
+ public void setUnfinishedStartups(Collection s) {
+ }
+
+ protected static class Stopper extends CancelCriterion {
+
+ @Override
+ public String cancelInProgress() {
+ checkFailure();
+ return null;
+ }
+
+ @Override
+ public RuntimeException generateCancelledException(Throwable e) {
+ return null;
+ }
+ }
+ private final Stopper stopper = new Stopper();
+
+ public CancelCriterion getCancelCriterion() {
+ return stopper;
+ }
+
+ /* (non-Javadoc)
+ * @see com.gemstone.gemfire.distributed.internal.DM#getMembershipManager()
+ */
+ public MembershipManager getMembershipManager() {
+ // no membership manager
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.gemstone.gemfire.distributed.internal.DM#getRootCause()
+ */
+ public Throwable getRootCause() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see com.gemstone.gemfire.distributed.internal.DM#setRootCause(java.lang.Throwable)
+ */
+ public void setRootCause(Throwable t) {
+ }
+
+ /* (non-Javadoc)
+ * @see com.gemstone.gemfire.distributed.internal.DM#getMembersOnThisHost()
+ * @since gemfire59poc
+ */
+ public Set<InternalDistributedMember> getMembersInThisZone() {
+ return this.allIds;
+ }
+
+ public void acquireGIIPermitUninterruptibly() {
+ }
+
+ public void releaseGIIPermit() {
+ }
+
+ public int getDistributedSystemId() {
+ return getSystem().getConfig().getDistributedSystemId();
+ }
+
+ public boolean enforceUniqueZone() {
+ return system.getConfig().getEnforceUniqueHost() || system.getConfig().getRedundancyZone() != null;
+ }
+
+ public boolean areInSameZone(InternalDistributedMember member1,
+ InternalDistributedMember member2) {
+ return false;
+ }
+
+ public boolean areOnEquivalentHost(InternalDistributedMember member1,
+ InternalDistributedMember member2) {
+ return member1 == member2;
+ }
+
+ public Set<InternalDistributedMember> getMembersInSameZone(
+ InternalDistributedMember acceptedMember) {
+ return Collections.singleton(acceptedMember);
+ }
+
+ public Set<InetAddress> getEquivalents(InetAddress in) {
+ Set<InetAddress> value = new HashSet<InetAddress>();
+ value.add(this.getId().getInetAddress());
+ return value;
+ }
+
+ public Set<DistributedMember> getGroupMembers(String group) {
+ if (getDistributionManagerId().getGroups().contains(group)) {
+ return Collections.singleton((DistributedMember)getDistributionManagerId());
+ } else {
+ return Collections.emptySet();
+ }
+ }
+
+ public void addHostedLocators(InternalDistributedMember member, Collection<String> locators, boolean isSharedConfigurationEnabled) {
+ // no-op
+ }
+
+ public Collection<String> getHostedLocators(InternalDistributedMember member) {
+ return Collections.<String>emptyList();
+ }
+
+ public Map<InternalDistributedMember, Collection<String>> getAllHostedLocators() {
+ return Collections.<InternalDistributedMember, Collection<String>>emptyMap();
+ }
+
+ @Override
+ public Set getNormalDistributionManagerIds() {
+ return getDistributionManagerIds();
+ }
+
+ @Override
+ public Map<InternalDistributedMember, Collection<String>> getAllHostedLocatorsWithSharedConfiguration() {
+ return Collections.<InternalDistributedMember, Collection<String>>emptyMap();
+ }
+
+ @Override
+ public void forceUDPMessagingForCurrentThread() {
+ // no-op for loners
+ }
+
+ @Override
+ public void releaseUDPMessagingForCurrentThread() {
+ // no-op for loners
+ }
+
+ @Override
+ public boolean isSharedConfigurationServiceEnabledForDS() {
+ //return false for loner
+ return false;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/5beaaedc/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/InternalDistributedMember.java
----------------------------------------------------------------------
diff --cc geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/InternalDistributedMember.java
index 8b5c279,0000000..81058f8
mode 100755,000000..100755
--- a/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/InternalDistributedMember.java
+++ b/geode-core/src/main/java/com/gemstone/gemfire/distributed/internal/membership/InternalDistributedMember.java
@@@ -1,1304 -1,0 +1,1304 @@@
+/*
+ * 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 com.gemstone.gemfire.distributed.internal.membership;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.EOFException;
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.net.Inet4Address;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import com.gemstone.gemfire.DataSerializer;
+import com.gemstone.gemfire.InternalGemFireError;
+import com.gemstone.gemfire.cache.UnsupportedVersionException;
+import com.gemstone.gemfire.distributed.DistributedMember;
+import com.gemstone.gemfire.distributed.DurableClientAttributes;
+import com.gemstone.gemfire.distributed.Role;
+import com.gemstone.gemfire.distributed.internal.DistributionAdvisor.ProfileId;
+import com.gemstone.gemfire.distributed.internal.DistributionManager;
+import com.gemstone.gemfire.internal.Assert;
+import com.gemstone.gemfire.internal.DataSerializableFixedID;
+import com.gemstone.gemfire.internal.InternalDataSerializer;
+import com.gemstone.gemfire.internal.OSProcess;
+import com.gemstone.gemfire.internal.SocketCreator;
+import com.gemstone.gemfire.internal.Version;
+import com.gemstone.gemfire.internal.cache.versions.VersionSource;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
+
+/**
+ * This is the fundamental representation of a member of a GemFire distributed
+ * system.
+ */
- public final class InternalDistributedMember
++public class InternalDistributedMember
+ implements DistributedMember,
+ Externalizable, DataSerializableFixedID, ProfileId,
+ VersionSource<DistributedMember>
+{
+ private final static long serialVersionUID = -2785249969777296507L;
+
+ // whether to show NetMember components in toString()
+ private final boolean SHOW_NETMEMBER = Boolean.getBoolean("gemfire.show_netmembers");
+
+ protected NetMember netMbr; // the underlying member object, e.g. from JGroups
+
+ /**
+ * This is the direct channel port. The underlying NetMember must be able to
+ * serialize and deliver this value.
+ */
+ private int dcPort = -1;
+
+ /**
+ * This is the process id of this member on its machine. The underlying
+ * NetMember must be able to serialize and deliver this value.
+ */
+ private int vmPid = -1;
+
+ /**
+ * This is a representation of the type of VM. The underlying NetMember must
+ * be able to serialize and deliver this value.
+ */
+ private int vmKind = DistributionManager.NORMAL_DM_TYPE;
+
+ /**
+ * This is the view identifier where this ID was born, or zero if this is
+ * a loner member
+ */
+ private int vmViewId = -1;
+
+ /**
+ * whether this is a partial member ID (without roles, durable attributes).
+ * We use partial IDs in EventID objects to reduce their size. It would be
+ * better to use canonical IDs but there is currently no central mechanism
+ * that would allow that for both server and client identifiers
+ */
+ private boolean isPartial;
+
+ /** Internal list of group/role names for this member. */
+ private String[] groups;
+
+ /**
+ * The roles, if any, of this member. Lazily created first time getRoles()
+ * is called.
+ */
+ private volatile Set<Role> rolesSet = null;
+
+ /** lock object used when getting/setting roles/rolesSet fields */
+ private final Object rolesLock = new Object();
+
+ /**
+ * The name of this member's distributed system connection.
+ * @see com.gemstone.gemfire.distributed.DistributedSystem#getName
+ */
+ private String name = null;
+
+ /**
+ * Unique tag (such as randomly generated bytes) to help enforce uniqueness.
+ * Note: this should be displayable.
+ */
+ private String uniqueTag = null;
+
+ /** serialization bit mask */
+ private static final int SB_ENABLED_MASK = 0x1;
+
+ /** serialization bit mask */
+ private static final int COORD_ENABLED_MASK = 0x2;
+
+ /** partial ID bit mask */
+ private static final int PARTIAL_ID_MASK = 0x4;
+
+ /** product version bit mask */
+ private static final int VERSION_MASK = 0x8;
+
+ /**
+ * Representing the host name of this member.
+ */
+ private String hostName = null;
+
+ private transient short version = Version.CURRENT_ORDINAL;
+ private transient Version versionObj = Version.CURRENT;
+
+ /**
+ * User-defined attributes (id and timeout) used by durable clients.
+ */
+ private DurableClientAttributes durableClientAttributes = null;
+
+ /** The versions in which this message was modified */
+ private static final Version[] dsfidVersions = new Version[] {
+ Version.GFE_71, Version.GFE_90 };
+
+ private void defaultToCurrentHost() {
+ this.vmPid = OSProcess.getId();
+ try {
+ if (SocketCreator.resolve_dns) {
+ this.hostName = SocketCreator.getHostName(SocketCreator.getLocalHost());
+ }
+ else {
+ this.hostName = SocketCreator.getLocalHost().getHostAddress();
+ }
+ }
+ catch(UnknownHostException ee){
+ throw new InternalGemFireError(ee);
+ }
+ synchPayload();
+ }
+
+
+ // Used only by Externalization
+ public InternalDistributedMember() {
+ this.groups = new String[0];
+ }
+
+ /**
+ * Construct a InternalDistributedMember. All fields are specified.<p>
+ *
+ * This, and the following constructor are the only valid ways to create an ID
+ * for a distributed member for use
+ * in the P2P cache. Use of other constructors can break network-partition-detection.
+ *
+ * @param i
+ * @param p
+ * the membership port
+ * @param splitBrainEnabled whether this feature is enabled for the member
+ * @param canBeCoordinator whether the member is eligible to be the membership coordinator
+ * @param attr
+ * the member's attributes
+ */
+ public InternalDistributedMember(InetAddress i, int p,
+ boolean splitBrainEnabled, boolean canBeCoordinator, MemberAttributes attr) {
+ this.dcPort = attr.getPort();
+ this.vmPid = attr.getVmPid();
+ this.vmKind = attr.getVmKind();
+ this.vmViewId = attr.getVmViewId();
+ this.name = attr.getName();
+ this.groups = attr.getGroups();
+ this.durableClientAttributes = attr.getDurableClientAttributes();
+ this.netMbr = MemberFactory.newNetMember(i, p, splitBrainEnabled, canBeCoordinator, Version.CURRENT_ORDINAL, attr);
+ this.hostName = SocketCreator.resolve_dns? SocketCreator.getHostName(i) : i.getHostAddress();
+ this.version = netMbr.getVersionOrdinal();
+ try {
+ this.versionObj = Version.fromOrdinal(version, false);
+ } catch (UnsupportedVersionException e) {
+ this.versionObj = Version.CURRENT;
+ }
+// checkHostName();
+ }
+
+
+ /**
+ * Construct a InternalDistributedMember based on the given NetMember.<p>
+ * This is not the preferred way of creating an instance since the NetMember
+ * may not have all required information (e.g., a JGroups address without
+ * direct-port and other information).
+ * @param m
+ */
+ public InternalDistributedMember(NetMember m) {
+ netMbr = m;
+
+ MemberAttributes attr = m.getAttributes();
+ this.hostName = SocketCreator.resolve_dns? SocketCreator.getHostName(m.getInetAddress()) :
+ m.getInetAddress().getHostAddress();
+// checkHostName();
+ if (attr == null) {
+ // no extended information available, so this address is crippled
+ }
+ else {
+ this.dcPort = attr.getPort();
+ this.vmPid = attr.getVmPid();
+ this.vmKind = attr.getVmKind();
+ this.vmViewId = attr.getVmViewId();
+ this.name = attr.getName();
+ this.groups = attr.getGroups();
+ this.durableClientAttributes = attr.getDurableClientAttributes();
+ }
+ this.version = m.getVersionOrdinal();
+ try {
+ this.versionObj = Version.fromOrdinal(version, false);
+ } catch (UnsupportedVersionException e) {
+ this.versionObj = Version.CURRENT;
+ }
+ cachedToString = null;
+ }
+
+ // private void checkHostName() {
+// // bug #44858: debug method to find who is putting a host name instead of addr into an ID
+// if (!SocketCreator.resolve_dns
+// && this.hostName != null && this.hostName.length() > 0
+// && !Character.isDigit(this.hostName.charAt(0))) {
+// throw new RuntimeException("found hostname that doesn't start with a digit: " + this.hostName);
+// }
+// }
+
+ /**
+ * Create a InternalDistributedMember referring to the current host (as defined by the given
+ * string).<p>
+ *
+ * <b>
+ * [bruce]THIS METHOD IS FOR TESTING ONLY. DO NOT USE IT TO CREATE IDs FOR
+ * USE IN THE PRODUCT. IT DOES NOT PROPERLY INITIALIZE ATTRIBUTES NEEDED
+ * FOR P2P FUNCTIONALITY.
+ * </b>
+ *
+ *
+ * @param i
+ * the hostname, must be for the current host
+ * @param p
+ * the membership listening port
+ * @throws UnknownHostException if the given hostname cannot be resolved
+ */
+ public InternalDistributedMember(String i, int p) throws UnknownHostException {
+ this(i, p, Version.CURRENT);
+ }
+
+ /**
+ * Create a InternalDistributedMember referring to the current host (as defined by the given
+ * string).<p>
+ *
+ * <b>
+ * [bruce]THIS METHOD IS FOR TESTING ONLY. DO NOT USE IT TO CREATE IDs FOR
+ * USE IN THE PRODUCT. IT DOES NOT PROPERLY INITIALIZE ATTRIBUTES NEEDED
+ * FOR P2P FUNCTIONALITY.
+ * </b>
+ *
+ *
+ * @param i
+ * the hostname, must be for the current host
+ * @param p
+ * the membership listening port
+ * @param version
+ * the version of this member
+ * @throws UnknownHostException if the given hostname cannot be resolved
+ */
+ public InternalDistributedMember(String i, int p, Version version) throws UnknownHostException {
+ this (i, p, version, MemberFactory.newNetMember(i, p));
+ }
+
+ /**
+ * Create a InternalDistributedMember referring to the current host (as defined by the given
+ * string).<p>
+ *
+ * <b>
+ * THIS METHOD IS FOR TESTING ONLY. DO NOT USE IT TO CREATE IDs FOR
+ * USE IN THE PRODUCT. IT DOES NOT PROPERLY INITIALIZE ATTRIBUTES NEEDED
+ * FOR P2P FUNCTIONALITY.
+ * </b>
+ **/
+ public InternalDistributedMember(String i, int p, Version version, NetMember netMember) throws UnknownHostException {
+ netMbr = netMember;
+ defaultToCurrentHost();
+ this.vmKind = DistributionManager.NORMAL_DM_TYPE;
+ this.versionObj = version;
+ }
+
+ /**
+ * Create a InternalDistributedMember referring to the current host
+ * (as defined by the given string) with additional info including optional
+ * connection name and an optional unique string. Currently these two
+ * optional fields (and this constructor) are only used by the
+ * LonerDistributionManager.<p>
+ *
+ * < b>
+ * [bruce]DO NOT USE THIS METHOD TO CREATE ANYTHING OTHER THAN A LONER ID
+ * WITHOUT TALKING TO ME FIRST. IT DOES NOT PROPERLY INITIALIZE THE ID.
+ * </b>
+ *
+ * @param host
+ * the hostname, must be for the current host
+ * @param p
+ * the membership listening port
+ * @param n
+ * gemfire properties connection name
+ * @param u
+ * unique string used make the member more unique
+ * @param vmKind the dmType
+ * @param groups the server groups / roles
+ * @param attr durable client attributes, if any
+ *
+ * @throws UnknownHostException if the given hostname cannot be resolved
+ */
+ public InternalDistributedMember(String host, int p, String n, String u,
+ int vmKind, String[] groups, DurableClientAttributes attr) throws UnknownHostException {
+ MemberAttributes mattr = new MemberAttributes(p,
+ com.gemstone.gemfire.internal.OSProcess.getId(),
+ vmKind, -1,
+ n,
+ groups, attr);
+ InetAddress addr = SocketCreator.toInetAddress(host);
+ netMbr = MemberFactory.newNetMember(addr, p, false, true, Version.CURRENT_ORDINAL, mattr);
+ defaultToCurrentHost();
+ this.name = n;
+ this.uniqueTag = u;
+ this.vmKind = vmKind;
+ this.dcPort = p;
+ this.durableClientAttributes = attr;
+ this.hostName = host;
+ this.vmPid = OSProcess.getId();
+ this.groups = groups;
+ }
+
+ /**
+ * Create a InternalDistributedMember referring to the current host (as defined by the given
+ * address).<p>
+ *
+ * <b>
+ * [bruce]THIS METHOD IS FOR TESTING ONLY. DO NOT USE IT TO CREATE IDs FOR
+ * USE IN THE PRODUCT. IT DOES NOT PROPERLY INITIALIZE ATTRIBUTES NEEDED
+ * FOR P2P FUNCTIONALITY.
+ * </b>
+ *
+ *
+ * @param i
+ * the hostname, must be for the current host
+ * @param p
+ * the membership listening port
+ */
+ public InternalDistributedMember(InetAddress i, int p) {
+ netMbr = MemberFactory.newNetMember(i, p);
+ defaultToCurrentHost();
+ }
+
+ /**
+ * Create a InternalDistributedMember as defined by the given address.
+ * <p>
+ *
+ * <b>
+ * [bruce]THIS METHOD IS FOR TESTING ONLY. DO NOT USE IT TO CREATE IDs FOR
+ * USE IN THE PRODUCT. IT DOES NOT PROPERLY INITIALIZE ATTRIBUTES NEEDED
+ * FOR P2P FUNCTIONALITY.
+ * </b>
+ *
+ * @param addr
+ * address of the server
+ * @param p
+ * the listening port of the server
+ * @param isCurrentHost
+ * true if the given host refers to the current host (bridge and
+ * gateway use false to create a temporary id for the OTHER side of a
+ * connection)
+ */
+ public InternalDistributedMember(InetAddress addr,
+ int p,
+ boolean isCurrentHost) {
+ netMbr = MemberFactory.newNetMember(addr, p);
+ if (isCurrentHost) {
+ defaultToCurrentHost();
+ }
+ }
+
+ /**
+ * Return the underlying host address
+ *
+ * @return the underlying host address
+ */
+ public InetAddress getInetAddress()
+ {
+ return netMbr.getInetAddress();
+ }
+
+ public NetMember getNetMember() {
+ return netMbr;
+ }
+
+ /**
+ * Return the underlying port (membership port)
+ * @return the underlying membership port
+ */
+ public int getPort()
+ {
+ return netMbr.getPort();
+ }
+
+
+ /**
+ * Returns the port on which the direct channel runs
+ */
+ public int getDirectChannelPort()
+ {
+ assert !this.isPartial;
+ return dcPort;
+ }
+
+ /**
+ * [GemStone] Returns the kind of VM that hosts the distribution manager with
+ * this address.
+ *
+ * @see com.gemstone.gemfire.distributed.internal.DistributionManager#getDMType()
+ * @see com.gemstone.gemfire.distributed.internal.DistributionManager#NORMAL_DM_TYPE
+ */
+ public int getVmKind()
+ {
+ return vmKind;
+ }
+
+ /**
+ * Returns the membership view ID that this member was born in. For
+ * backward compatibility reasons this is limited to 16 bits.
+ */
+ public int getVmViewId() {
+ return this.vmViewId;
+ }
+
+ /**
+ * Returns an unmodifiable Set of this member's Roles.
+ */
+ public Set<Role> getRoles() {
+ Set<Role> tmpRolesSet = this.rolesSet;
+ if (tmpRolesSet != null) {
+ return tmpRolesSet;
+ }
+ assert !this.isPartial;
+ synchronized (this.rolesLock) {
+ tmpRolesSet = this.rolesSet;
+ if (tmpRolesSet == null) {
+ final String[] tmpRoles = this.groups;
+ // convert array of string role names to array of Roles...
+ if (tmpRoles == null || tmpRoles.length == 0) {
+ tmpRolesSet = Collections.emptySet();
+ }
+ else {
+ tmpRolesSet = new HashSet<Role>(tmpRoles.length);
+ for (int i = 0; i < tmpRoles.length; i++) {
+ tmpRolesSet.add(InternalRole.getRole(tmpRoles[i]));
+ }
+ tmpRolesSet = Collections.unmodifiableSet(tmpRolesSet);
+ }
+ this.rolesSet = tmpRolesSet;
+ }
+ }
+ Assert.assertTrue(tmpRolesSet != null);
+ return tmpRolesSet;
+ }
+ public List<String> getGroups() {
+ return Collections.unmodifiableList(Arrays.asList(this.groups));
+ }
+
+ public void setGroups(String[] newGroups) {
+ assert !this.isPartial;
+ assert newGroups != null;
+ synchronized (this.rolesLock) {
+ this.groups = newGroups;
+ synchPayload();
+ this.rolesSet = null;
+ this.cachedToString = null;
+ }
+ }
+
+ private void synchPayload() {
+ netMbr.setAttributes(new MemberAttributes(dcPort, vmPid, vmKind,
+ vmViewId, name, groups, durableClientAttributes));
+ }
+
+ public void setVmKind(int p)
+ {
+ vmKind = p;
+ synchPayload();
+ cachedToString = null;
+ }
+
+ public void setVmViewId(int p) {
+ this.vmViewId = p;
+ synchPayload();
+ cachedToString = null;
+ }
+
+ /**
+ * [GemStone] Returns the process id of the VM that hosts the distribution
+ * manager with this address.
+ *
+ * @since 4.0
+ */
+ public int getVmPid()
+ {
+ return vmPid;
+ }
+
+ /**
+ * [GemStone] Sets the process id of the VM that hosts the distribution
+ * manager with this address.
+ *
+ * @since 4.0
+ */
+ public void setVmPid(int p)
+ {
+ this.vmPid = p;
+ synchPayload();
+ cachedToString = null;
+ }
+
+ /**
+ * Returns the name of this member's distributed system connection or null
+ * if no name was specified.
+ * @see com.gemstone.gemfire.distributed.DistributedSystem#getName
+ */
+ public String getName() {
+ String result = this.name;
+ if (result == null) {
+ result = "";
+ }
+ return result;
+ }
+
+ /**
+ * Returns this member's unique tag (such as randomly generated bytes) or
+ * null if no unique tag was created.
+ */
+ public String getUniqueTag() {
+ return this.uniqueTag;
+ }
+
+ /**
+ * Returns this client member's durable attributes or null if no durable
+ * attributes were created.
+ */
+ public DurableClientAttributes getDurableClientAttributes() {
+ assert !this.isPartial;
+ return this.durableClientAttributes;
+ }
+
+ /**
+ * implements the java.lang.Comparable interface
+ *
+ * @see java.lang.Comparable
+ * @param o -
+ * the Object to be compared
+ * @return a negative integer, zero, or a positive integer as this object is
+ * less than, equal to, or greater than the specified object.
+ * @exception java.lang.ClassCastException -
+ * if the specified object's type prevents it from being compared
+ * to this Object.
+ */
+ public int compareTo(DistributedMember o) {
+ return compareTo(o, true);
+ }
+
+ public int compareTo(DistributedMember o, boolean checkNetMembersIfEqual) {
+ if (this == o) {
+ return 0;
+ }
+ // obligatory type check
+ if ((o == null) || !(o instanceof InternalDistributedMember))
+ throw new ClassCastException(LocalizedStrings.InternalDistributedMember_INTERNALDISTRIBUTEDMEMBERCOMPARETO_COMPARISON_BETWEEN_DIFFERENT_CLASSES.toLocalizedString());
+ InternalDistributedMember other = (InternalDistributedMember)o;
+
+ int myPort = getPort();
+ int otherPort = other.getPort();
+ if (myPort < otherPort)
+ return -1;
+ if (myPort > otherPort)
+ return 1;
+
+
+ InetAddress myAddr = getInetAddress();
+ InetAddress otherAddr = other.getInetAddress();
+
+ // Discard null cases
+ if (myAddr == null && otherAddr == null) {
+ if (myPort < otherPort)
+ return -1;
+ else if (myPort > otherPort)
+ return 1;
+ else
+ return 0;
+ }
+ else if (myAddr == null) {
+ return -1;
+ }
+ else if (otherAddr == null)
+ return 1;
+
+ byte[] myBytes = myAddr.getAddress();
+ byte[] otherBytes = otherAddr.getAddress();
+
+ if (myBytes != otherBytes) {
+ for (int i = 0; i < myBytes.length; i++) {
+ if (i >= otherBytes.length)
+ return -1; // same as far as they go, but shorter...
+ if (myBytes[i] < otherBytes[i])
+ return -1;
+ if (myBytes[i] > otherBytes[i])
+ return 1;
+ }
+ if (myBytes.length > otherBytes.length)
+ return 1; // same as far as they go, but longer...
+ }
+
+ if (this.name == null && other.name == null) {
+ // do nothing
+ } else if (this.name == null) {
+ return -1;
+ }
+ else if (other.name == null) {
+ return 1;
+ }
+ else {
+ int i = this.name.compareTo(other.name);
+ if (i != 0) {
+ return i;
+ }
+ }
+
+ if (this.uniqueTag == null && other.uniqueTag == null) {
+ // not loners, so look at P2P view ID
+ if (this.vmViewId >= 0 && other.vmViewId >= 0) {
+ if (this.vmViewId < other.vmViewId) {
+ return -1;
+ } else if (this.vmViewId > other.vmViewId) {
+ return 1;
+ } // else they're the same, so continue
+ }
+ } else if (this.uniqueTag == null) {
+ return -1;
+ }
+ else if (other.uniqueTag == null) {
+ return 1;
+ }
+ else {
+ int i = this.uniqueTag.compareTo(other.uniqueTag);
+ if (i != 0) {
+ return i;
+ }
+ }
+
+ if (checkNetMembersIfEqual
+ && this.netMbr != null && other.netMbr != null) {
+ return this.netMbr.compareTo(other.netMbr);
+ } else {
+ return 0;
+ }
+
+ // purposely avoid comparing roles
+ // @todo Add durableClientAttributes to compare
+ }
+
+ @Override
+ public boolean equals(Object obj)
+ {
+ if (this == obj) {
+ return true;
+ }
+ // GemStone fix for 29125
+ if ((obj == null) || !(obj instanceof InternalDistributedMember)) {
+ return false;
+ }
+ return compareTo((InternalDistributedMember)obj) == 0;
+ }
+
+ @Override
+ public int hashCode()
+ {
+ int result = 0;
+ result = result + netMbr.getInetAddress().hashCode();
+ result = result + getPort();
+ return result;
+ }
+
+ private String shortName(String hostname)
+ {
+ if (hostname == null)
+ return "<null inet_addr hostname>";
+ int index = hostname.indexOf('.');
+
+ if (index > 0 && !Character.isDigit(hostname.charAt(0)))
+ return hostname.substring(0, index);
+ else
+ return hostname;
+ }
+
+
+ /** the cached string description of this object */
+ private transient String cachedToString;
+
+ @Override
+ public String toString()
+ {
+ String result = cachedToString;
+ if (result == null) {
+ String host;
+
+ InetAddress add = getInetAddress();
+ if (add.isMulticastAddress())
+ host = add.getHostAddress();
+ else {
+ // host = shortName(add.getHostName());
+ host = SocketCreator.resolve_dns? shortName(this.hostName) : this.hostName;
+ }
+ final StringBuilder sb = new StringBuilder();
+
+ sb.append(host);
+
+ String myName = getName();
+ if (vmPid > 0 || vmKind != DistributionManager.NORMAL_DM_TYPE || !"".equals(myName)) {
+ sb.append("(");
+
+ if (!"".equals(myName)) {
+ sb.append(myName);
+ if (vmPid > 0) {
+ sb.append(':');
+ }
+ }
+
+ if (vmPid > 0)
+ sb.append(Integer.toString(vmPid));
+
+ String vmStr = "";
+ switch (vmKind) {
+ case DistributionManager.NORMAL_DM_TYPE:
+ // vmStr = ":local"; // let this be silent
+ break;
+ case DistributionManager.LOCATOR_DM_TYPE:
+ vmStr = ":locator";
+ break;
+ case DistributionManager.ADMIN_ONLY_DM_TYPE:
+ vmStr = ":admin";
+ break;
+ case DistributionManager.LONER_DM_TYPE:
+ vmStr = ":loner";
+ break;
+ default:
+ vmStr = ":<unknown:" + vmKind + ">";
+ break;
+ }
+ sb.append(vmStr);
+ sb.append(")");
+ }
+ if (vmKind != DistributionManager.LONER_DM_TYPE && netMbr.preferredForCoordinator()) {
+ sb.append("<ec>");
+ }
+ if (this.vmViewId >= 0) {
+ sb.append("<v" + this.vmViewId + ">");
+ }
+ sb.append(":");
+ sb.append(getPort());
+
+// if (dcPort > 0 && vmKind != DistributionManager.LONER_DM_TYPE) {
+// sb.append("/");
+// sb.append(Integer.toString(dcPort));
+// }
+
+ if (vmKind == DistributionManager.LONER_DM_TYPE) {
+ // add some more info that was added in 4.2.1 for loner bridge clients
+ // impact on non-bridge loners is ok
+ if (this.uniqueTag != null && this.uniqueTag.length() != 0) {
+ sb.append(":").append(this.uniqueTag);
+ }
+ if (this.name != null && this.name.length() != 0) {
+ sb.append(":").append(this.name);
+ }
+ }
+
+ // add version if not current
+ if (this.version != Version.CURRENT.ordinal()) {
+ sb.append("(version:").append(Version.toString(this.version))
+ .append(')');
+ }
+
+ if (SHOW_NETMEMBER) {
+ sb.append("[[").append(this.netMbr).append("]]");
+ }
+
+ // leave out Roles on purpose
+
+// if (netMbr instanceof GMSMember) {
+// sb.append("(UUID=").append(((GMSMember)netMbr).getUUID()).append(")");
+// }
+
+ result = sb.toString();
+ cachedToString = result;
+ }
+ return result;
+ }
+
+ private void readVersion(int flags, DataInput in) throws IOException {
+ if ((flags & VERSION_MASK) != 0) {
+ this.version = Version.readOrdinal(in);
+ this.versionObj = Version.fromOrdinalNoThrow(this.version, false);
+ } else {
+ // prior to 7.1 member IDs did not serialize their version information
+ Version v = InternalDataSerializer.getVersionForDataStreamOrNull(in);
+ if (v != null) {
+ this.versionObj = v;
+ this.version = v.ordinal();
+ }
+ }
+ }
+
+ /**
+ * For Externalizable
+ *
+ * @see Externalizable
+ */
+ public void writeExternal(ObjectOutput out) throws IOException {
+ Assert.assertTrue(vmKind > 0);
+
+ // do it the way we like
+ byte[] address = getInetAddress().getAddress();
+
+ out.writeInt(address.length); // IPv6 compatible
+ out.write(address);
+ out.writeInt(getPort());
+
+ DataSerializer.writeString(this.hostName, out);
+
+ int flags = 0;
+ if (netMbr.splitBrainEnabled()) flags |= SB_ENABLED_MASK;
+ if (netMbr.preferredForCoordinator()) flags |= COORD_ENABLED_MASK;
+ if (this.isPartial) flags |= PARTIAL_ID_MASK;
+ // always write product version but enable reading from older versions
+ // that do not have it
+ flags |= VERSION_MASK;
+ out.writeByte((byte)(flags & 0xff));
+
+ out.writeInt(dcPort);
+ out.writeInt(vmPid);
+ out.writeInt(vmKind);
+ out.writeInt(vmViewId);
+ DataSerializer.writeStringArray(this.groups, out);
+
+ DataSerializer.writeString(this.name, out);
+ DataSerializer.writeString(this.uniqueTag, out);
+ DataSerializer.writeString(this.durableClientAttributes==null ? "" : this.durableClientAttributes.getId(), out);
+ DataSerializer.writeInteger(Integer.valueOf(this.durableClientAttributes==null ? 300 : this.durableClientAttributes.getTimeout()), out);
+ Version.writeOrdinal(out, this.version, true);
+ netMbr.writeAdditionalData(out);
+ }
+
+ /**
+ * For Externalizable
+ *
+ * @see Externalizable
+ */
+ public void readExternal(ObjectInput in)
+ throws IOException, ClassNotFoundException {
+ int len = in.readInt(); // IPv6 compatible
+ byte addr[] = new byte[len];
+ in.readFully(addr);
+ InetAddress inetAddr = InetAddress.getByAddress(addr);
+ int port = in.readInt();
+
+ this.hostName = DataSerializer.readString(in);
+
+ int flags = in.readUnsignedByte();
+ boolean sbEnabled = (flags & SB_ENABLED_MASK) != 0;
+ boolean elCoord = (flags & COORD_ENABLED_MASK) != 0;
+ this.isPartial = (flags & PARTIAL_ID_MASK) != 0;
+
+ this.dcPort = in.readInt();
+ this.vmPid = in.readInt();
+ this.vmKind = in.readInt();
+ this.vmViewId = in.readInt();
+ this.groups = DataSerializer.readStringArray(in);
+
+ this.name = DataSerializer.readString(in);
+ this.uniqueTag = DataSerializer.readString(in);
+ String durableId = DataSerializer.readString(in);
+ int durableTimeout = DataSerializer.readInteger(in).intValue();
+ this.durableClientAttributes = new DurableClientAttributes(durableId, durableTimeout);
+
+ readVersion(flags, in);
+
+ netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord, version,
+ new MemberAttributes(dcPort, vmPid, vmKind, vmViewId, name, groups, durableClientAttributes));
+ if (this.version >= Version.GFE_90.ordinal()) {
+ try {
+ netMbr.readAdditionalData(in);
+ } catch (java.io.EOFException e) {
+ // old version quand-meme
+ }
+ }
+
+ Assert.assertTrue(this.vmKind > 0);
+ }
+
+ public int getDSFID() {
+ return DISTRIBUTED_MEMBER;
+ }
+
+ public void toData(DataOutput out) throws IOException {
+ toDataPre_GFE_9_0_0_0(out);
+ if (this.version >= Version.GFE_90.ordinal()) {
+ getNetMember().writeAdditionalData(out);
+ }
+ }
+
+
+ public void toDataPre_GFE_9_0_0_0(DataOutput out) throws IOException {
+ Assert.assertTrue(vmKind > 0);
+ // NOTE: If you change the serialized format of this class
+ // then bump Connection.HANDSHAKE_VERSION since an
+ // instance of this class is sent during Connection handshake.
+ DataSerializer.writeInetAddress(getInetAddress(), out);
+ out.writeInt(getPort());
+
+ DataSerializer.writeString(this.hostName, out);
+
+ int flags = 0;
+ if (netMbr.splitBrainEnabled()) flags |= SB_ENABLED_MASK;
+ if (netMbr.preferredForCoordinator()) flags |= COORD_ENABLED_MASK;
+ if (this.isPartial) flags |= PARTIAL_ID_MASK;
+ // always write product version but enable reading from older versions
+ // that do not have it
+ flags |= VERSION_MASK;
+ out.writeByte((byte)(flags & 0xff));
+
+ out.writeInt(dcPort);
+ out.writeInt(vmPid);
+ out.writeByte(vmKind);
+ DataSerializer.writeStringArray(this.groups, out);
+
+ DataSerializer.writeString(this.name, out);
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ DataSerializer.writeString(this.uniqueTag, out);
+ } else { // added in 6.5 for unique identifiers in P2P
+ DataSerializer.writeString(String.valueOf(this.vmViewId), out);
+ }
+ DataSerializer.writeString(this.durableClientAttributes==null ? "" : this.durableClientAttributes.getId(), out);
+ DataSerializer.writeInteger(Integer.valueOf(this.durableClientAttributes==null ? 300 : this.durableClientAttributes.getTimeout()), out);
+ Version.writeOrdinal(out, this.version, true);
+ }
+
+ public void toDataPre_GFE_7_1_0_0(DataOutput out) throws IOException {
+ Assert.assertTrue(vmKind > 0);
+ // [bruce] disabled to allow post-connect setting of the port for loner systems
+// Assert.assertTrue(getPort() > 0);
+// if (this.getPort() == 0) {
+// InternalDistributedSystem.getLoggerI18n().warning(LocalizedStrings.DEBUG,
+// "Serializing ID with zero port", new Exception("Stack trace"));
+// }
+
+ // NOTE: If you change the serialized format of this class
+ // then bump Connection.HANDSHAKE_VERSION since an
+ // instance of this class is sent during Connection handshake.
+ DataSerializer.writeInetAddress(getInetAddress(), out);
+ out.writeInt(getPort());
+
+ DataSerializer.writeString(this.hostName, out);
+
+ int flags = 0;
+ if (netMbr.splitBrainEnabled()) flags |= SB_ENABLED_MASK;
+ if (netMbr.preferredForCoordinator()) flags |= COORD_ENABLED_MASK;
+ if (this.isPartial) flags |= PARTIAL_ID_MASK;
+ out.writeByte((byte)(flags & 0xff));
+
+ out.writeInt(dcPort);
+ out.writeInt(vmPid);
+ out.writeByte(vmKind);
+ DataSerializer.writeStringArray(this.groups, out);
+
+ DataSerializer.writeString(this.name, out);
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ DataSerializer.writeString(this.uniqueTag, out);
+ } else { // added in 6.5 for unique identifiers in P2P
+ DataSerializer.writeString(String.valueOf(this.vmViewId), out);
+ }
+ DataSerializer.writeString(this.durableClientAttributes==null ? "" : this.durableClientAttributes.getId(), out);
+ DataSerializer.writeInteger(Integer.valueOf(this.durableClientAttributes==null ? 300 : this.durableClientAttributes.getTimeout()), out);
+
+ }
+
+ public void fromData(DataInput in)
+ throws IOException, ClassNotFoundException {
+ fromDataPre_GFE_9_0_0_0(in);
+ // just in case this is just a non-versioned read
+ // from a file we ought to check the version
+ if (this.version >= Version.GFE_90.ordinal()) {
+ try {
+ netMbr.readAdditionalData(in);
+ } catch (EOFException e) {
+ // nope - it's from a pre-GEODE client or WAN site
+ }
+ }
+ }
+
+ public void fromDataPre_GFE_9_0_0_0(DataInput in)
+ throws IOException, ClassNotFoundException {
+ InetAddress inetAddr = DataSerializer.readInetAddress(in);
+ int port = in.readInt();
+
+ this.hostName = DataSerializer.readString(in);
+ this.hostName = SocketCreator.resolve_dns? SocketCreator.getCanonicalHostName(inetAddr, hostName) : inetAddr.getHostAddress();
+
+ int flags = in.readUnsignedByte();
+ boolean sbEnabled = (flags & SB_ENABLED_MASK) != 0;
+ boolean elCoord = (flags & COORD_ENABLED_MASK) != 0;
+ this.isPartial = (flags & PARTIAL_ID_MASK) != 0;
+
+ this.dcPort = in.readInt();
+ this.vmPid = in.readInt();
+ this.vmKind = in.readUnsignedByte();
+ this.groups = DataSerializer.readStringArray(in);
+
+ this.name = DataSerializer.readString(in);
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ this.uniqueTag = DataSerializer.readString(in);
+ } else {
+ String str = DataSerializer.readString(in);
+ if (str != null) { // backward compatibility from earlier than 6.5
+ this.vmViewId = Integer.parseInt(str);
+ }
+ }
+
+ String durableId = DataSerializer.readString(in);
+ int durableTimeout = DataSerializer.readInteger(in).intValue();
+ this.durableClientAttributes = new DurableClientAttributes(durableId, durableTimeout);
+
+ readVersion(flags, in);
+
+ MemberAttributes attr = new MemberAttributes(this.dcPort, this.vmPid,
+ this.vmKind, this.vmViewId, this.name, this.groups, this.durableClientAttributes);
+ netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord, version, attr);
+
+ synchPayload();
+
+ Assert.assertTrue(this.vmKind > 0);
+// Assert.assertTrue(getPort() > 0);
+ }
+
+ public void fromDataPre_GFE_7_1_0_0(DataInput in) throws IOException, ClassNotFoundException {
+ InetAddress inetAddr = DataSerializer.readInetAddress(in);
+ int port = in.readInt();
+
+ this.hostName = DataSerializer.readString(in);
+ this.hostName = SocketCreator.resolve_dns? SocketCreator.getCanonicalHostName(inetAddr, hostName) : inetAddr.getHostAddress();
+
+ int flags = in.readUnsignedByte();
+ boolean sbEnabled = (flags & SB_ENABLED_MASK) != 0;
+ boolean elCoord = (flags & COORD_ENABLED_MASK) != 0;
+ this.isPartial = (flags & PARTIAL_ID_MASK) != 0;
+
+ this.dcPort = in.readInt();
+ this.vmPid = in.readInt();
+ this.vmKind = in.readUnsignedByte();
+ this.groups = DataSerializer.readStringArray(in);
+
+ this.name = DataSerializer.readString(in);
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ this.uniqueTag = DataSerializer.readString(in);
+ } else {
+ String str = DataSerializer.readString(in);
+ if (str != null) { // backward compatibility from earlier than 6.5
+ this.vmViewId = Integer.parseInt(str);
+ }
+ }
+
+ String durableId = DataSerializer.readString(in);
+ int durableTimeout = DataSerializer.readInteger(in).intValue();
+ this.durableClientAttributes = new DurableClientAttributes(durableId, durableTimeout);
+
+ MemberAttributes attr = new MemberAttributes(this.dcPort, this.vmPid,
+ this.vmKind, this.vmViewId, this.name, this.groups, this.durableClientAttributes);
+ netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord,
+ InternalDataSerializer.getVersionForDataStream(in).ordinal(), attr);
+
+ synchPayload();
+
+ Assert.assertTrue(this.vmKind > 0);
+ }
+
+ /** this writes just the parts of the ID that are needed for comparisons and communications */
+ public static InternalDistributedMember readEssentialData(DataInput in)
+ throws IOException, ClassNotFoundException {
+ final InternalDistributedMember mbr = new InternalDistributedMember();
+ mbr._readEssentialData(in);
+ return mbr;
+ }
+
+ private void _readEssentialData(DataInput in)
+ throws IOException, ClassNotFoundException {
+ this.isPartial = true;
+ InetAddress inetAddr = DataSerializer.readInetAddress(in);
+ int port = in.readInt();
+
+ this.hostName = SocketCreator.resolve_dns? SocketCreator.getHostName(inetAddr) : inetAddr.getHostAddress();
+
+ int flags = in.readUnsignedByte();
+ boolean sbEnabled = (flags & SB_ENABLED_MASK) != 0;
+ boolean elCoord = (flags & COORD_ENABLED_MASK) != 0;
+
+ this.vmKind = in.readUnsignedByte();
+
+
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ this.uniqueTag = DataSerializer.readString(in);
+ } else {
+ String str = DataSerializer.readString(in);
+ if (str != null) { // backward compatibility from earlier than 6.5
+ this.vmViewId = Integer.parseInt(str);
+ }
+ }
+
+ this.name = DataSerializer.readString(in);
+
+ MemberAttributes attr = new MemberAttributes(this.dcPort, this.vmPid,
+ this.vmKind, this.vmViewId, this.name, this.groups, this.durableClientAttributes);
+ netMbr = MemberFactory.newNetMember(inetAddr, port, sbEnabled, elCoord,
+ InternalDataSerializer.getVersionForDataStream(in).ordinal(), attr);
+
+ synchPayload();
+
+ if (InternalDataSerializer.getVersionForDataStream(in).compareTo(Version.GFE_90)>=0) {
+ netMbr.readAdditionalData(in);
+ }
+ }
+
+
+ public void writeEssentialData(DataOutput out) throws IOException {
+ Assert.assertTrue(vmKind > 0);
+ DataSerializer.writeInetAddress(getInetAddress(), out);
+ out.writeInt(getPort());
+
+ int flags = 0;
+ if (netMbr.splitBrainEnabled()) flags |= SB_ENABLED_MASK;
+ if (netMbr.preferredForCoordinator()) flags |= COORD_ENABLED_MASK;
+ flags |= PARTIAL_ID_MASK;
+ out.writeByte((byte)(flags & 0xff));
+
+// out.writeInt(dcPort);
+ out.writeByte(vmKind);
+
+ if (this.vmKind == DistributionManager.LONER_DM_TYPE) {
+ DataSerializer.writeString(this.uniqueTag, out);
+ } else { // added in 6.5 for unique identifiers in P2P
+ DataSerializer.writeString(String.valueOf(this.vmViewId), out);
+ }
+ // write name last to fix bug 45160
+ DataSerializer.writeString(this.name, out);
+
+ if (InternalDataSerializer.getVersionForDataStream(out).compareTo(Version.GFE_90)>=0) {
+ netMbr.writeAdditionalData(out);
+ }
+ }
+
+ /**
+ * [GemStone] Set the direct channel port
+ */
+ public void setDirectChannelPort(int p)
+ {
+ dcPort = p;
+ synchPayload();
+ }
+
+ /**
+ * Set the membership port. This is done in loner systems using
+ * client/server connection information to help form a unique ID
+ */
+ public void setPort(int p) {
+ assert this.vmKind == DistributionManager.LONER_DM_TYPE;
+ this.netMbr.setPort(p);
+ synchPayload();
+ cachedToString = null;
+ }
+
+ /** drop the cached toString rep of this ID */
+ public void dropCachedString() {
+ this.cachedToString = null;
+ }
+
+ public String getHost() {
+ return this.netMbr.getInetAddress().getCanonicalHostName();
+ }
+
+ public int getProcessId() {
+ return this.vmPid;
+ }
+
+ public String getId() {
+ return toString();
+ }
+ /*if (this.ipAddr == null) {
+ return "<null>";
+ }
+ else {
+ StringBuffer sb = new StringBuffer();
+ InetAddress addr = this.ipAddr.getIpAddress();
+ if(addr.isMulticastAddress()) {
+ sb.append(addr.getHostAddress());
+ } else {
+ appendShortName(addr.getHostName(), sb);
+ }
+ if (this.vmPid != 0) {
+ sb.append("(");
+ sb.append(this.vmPid);
+ sb.append(")");
+ }
+ sb.append(":");
+ sb.append(this.ipAddr.getPort());
+ return sb.toString();
+ }
+ }
+
+ // Helper method for getId()... copied from IpAddress.
+ private void appendShortName(String hostname, StringBuffer sb) {
+ if (hostname == null) return;
+ int index = hostname.indexOf('.');
+ if(index > 0 && !Character.isDigit(hostname.charAt(0))) {
+ sb.append(hostname.substring(0, index));
+ } else {
+ sb.append(hostname);
+ }
+ }*/
+
+ public final void setVersionObjectForTest(Version v) {
+ this.version = v.ordinal();
+ this.versionObj = v;
+ netMbr.setVersion(v);
+ }
+
+ public final Version getVersionObject() {
+ return this.versionObj;
+ }
+
+ @Override
+ public Version[] getSerializationVersions() {
+ return dsfidVersions;
+ }
+
+
+ @Override
+ public int getSizeInBytes() {
+
+ int size = 0;
+
+ // ipaddr: 1 byte length + 4 bytes (IPv4) or 16 bytes (IPv6)
+ if (netMbr.getInetAddress() instanceof Inet4Address){
+ size += 5;
+ } else {
+ size += 17;
+ }
+
+ // port: 4 bytes
+ // flags: 1 byte
+ //vmKind: 1 byte
+ size += 6;
+
+ // viewID: String(1+1+numchars)
+ size += (2+ String.valueOf(this.vmViewId).length());
+
+ // empty name: String(1+1)
+ size += 2;
+
+ return size;
+ }
+}