use of org.apache.geode.i18n.StringId in project geode by apache.
the class DistributionManager method handleConsoleShutdown.
/**
* Makes note of a console that has shut down.
*
* @param theId The id of the console shutting down
* @param crashed only true if we detect this id to be gone from a javagroup view
*
* @see AdminConsoleDisconnectMessage#process
*/
public void handleConsoleShutdown(InternalDistributedMember theId, boolean crashed, String reason) {
boolean removedConsole = false;
boolean removedMember = false;
synchronized (this.membersLock) {
// In this case we need for the normal DS to shutdown or crash.
if (!this.members.containsKey(theId)) {
if (logger.isDebugEnabled())
logger.debug("DistributionManager: removing admin member <{}>; crashed = {}; reason = {}", theId, crashed, reason);
Set tmp = new HashSet(this.membersAndAdmin);
if (tmp.remove(theId)) {
// without locking.
if (tmp.isEmpty()) {
tmp = Collections.EMPTY_SET;
} else {
tmp = Collections.unmodifiableSet(tmp);
}
this.membersAndAdmin = tmp;
removedMember = true;
} else {
// Don't get upset since this can happen twice due to
// an explicit remove followed by an implicit one caused
// by a JavaGroup view change
}
}
removeHostedLocators(theId);
}
synchronized (this.adminConsolesLock) {
if (this.adminConsoles.contains(theId)) {
removedConsole = true;
Set tmp = new HashSet(this.adminConsoles);
tmp.remove(theId);
if (tmp.isEmpty()) {
tmp = Collections.EMPTY_SET;
} else {
tmp = Collections.unmodifiableSet(tmp);
}
this.adminConsoles = tmp;
}
}
if (removedMember) {
for (Iterator iter = allMembershipListeners.iterator(); iter.hasNext(); ) {
MembershipListener listener = (MembershipListener) iter.next();
listener.memberDeparted(theId, crashed);
}
}
if (removedConsole) {
StringId msg = null;
if (crashed) {
msg = LocalizedStrings.DistributionManager_ADMINISTRATION_MEMBER_AT_0_CRASHED_1;
} else {
msg = LocalizedStrings.DistributionManager_ADMINISTRATION_MEMBER_AT_0_CLOSED_1;
}
logger.info(LocalizedMessage.create(msg, new Object[] { theId, reason }));
}
redundancyZones.remove(theId);
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class DistributionManager method handleManagerDeparture.
/**
* used by the DistributedMembershipListener and startup and shutdown operations, this method
* decrements the number of nodes and handles lower-level clean up of the resources used by the
* departed manager
*/
public void handleManagerDeparture(InternalDistributedMember theId, boolean p_crashed, String p_reason) {
boolean crashed = p_crashed;
String reason = p_reason;
AlertAppender.getInstance().removeAlertListener(theId);
// but still in the javagroup view.
try {
selectElder();
} catch (DistributedSystemDisconnectedException e) {
// keep going
}
int vmType = theId.getVmKind();
if (vmType == ADMIN_ONLY_DM_TYPE) {
removeUnfinishedStartup(theId, true);
handleConsoleShutdown(theId, crashed, reason);
return;
}
// not an admin VM...
if (!isCurrentMember(theId)) {
// fault tolerance
return;
}
removeUnfinishedStartup(theId, true);
if (removeManager(theId, crashed, reason)) {
if (theId.getVmKind() != DistributionManager.LOCATOR_DM_TYPE) {
this.stats.incNodes(-1);
}
StringId msg;
if (crashed && !isCloseInProgress()) {
msg = LocalizedStrings.DistributionManager_MEMBER_AT_0_UNEXPECTEDLY_LEFT_THE_DISTRIBUTED_CACHE_1;
addMemberEvent(new MemberCrashedEvent(theId, reason));
} else {
msg = LocalizedStrings.DistributionManager_MEMBER_AT_0_GRACEFULLY_LEFT_THE_DISTRIBUTED_CACHE_1;
addMemberEvent(new MemberDepartedEvent(theId, reason));
}
logger.info(LocalizedMessage.create(msg, new Object[] { theId, prettifyReason(reason) }));
// Remove this manager from the serialQueueExecutor.
if (this.serialQueuedExecutorPool != null) {
serialQueuedExecutorPool.handleMemberDeparture(theId);
}
}
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class InternalDataSerializer method _register.
public static DataSerializer _register(DataSerializer s, boolean distribute) {
final int id = s.getId();
DataSerializer dsForMarkers = s;
if (id == 0) {
throw new IllegalArgumentException(LocalizedStrings.InternalDataSerializer_CANNOT_CREATE_A_DATASERIALIZER_WITH_ID_0.toLocalizedString());
}
final Class[] classes = s.getSupportedClasses();
if (classes == null || classes.length == 0) {
final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_0_HAS_NO_SUPPORTED_CLASSES_ITS_GETSUPPORTEDCLASSES_METHOD_MUST_RETURN_AT_LEAST_ONE_CLASS;
throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
}
for (Class aClass : classes) {
if (aClass == null) {
final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_GETSUPPORTEDCLASSES_METHOD_FOR_0_RETURNED_AN_ARRAY_THAT_CONTAINED_A_NULL_ELEMENT;
throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
} else if (aClass.isArray()) {
final StringId msg = LocalizedStrings.InternalDataSerializer_THE_DATASERIALIZER_GETSUPPORTEDCLASSES_METHOD_FOR_0_RETURNED_AN_ARRAY_THAT_CONTAINED_AN_ARRAY_CLASS_WHICH_IS_NOT_ALLOWED_SINCE_ARRAYS_HAVE_BUILTIN_SUPPORT;
throw new IllegalArgumentException(msg.toLocalizedString(s.getClass().getName()));
}
}
final Integer idx = id;
boolean retry;
Marker oldMarker = null;
final Marker m = new InitMarker();
do {
retry = false;
Object oldSerializer = idsToSerializers.putIfAbsent(idx, m);
if (oldSerializer != null) {
if (oldSerializer instanceof Marker) {
retry = !idsToSerializers.replace(idx, oldSerializer, m);
if (!retry) {
oldMarker = (Marker) oldSerializer;
}
} else if (oldSerializer.getClass().equals(s.getClass())) {
// We've already got one of these registered
if (distribute) {
sendRegistrationMessage(s);
}
return (DataSerializer) oldSerializer;
} else {
DataSerializer other = (DataSerializer) oldSerializer;
throw new IllegalStateException(LocalizedStrings.InternalDataSerializer_A_DATASERIALIZER_OF_CLASS_0_IS_ALREADY_REGISTERED_WITH_ID_1_SO_THE_DATASERIALIZER_OF_CLASS_2_COULD_NOT_BE_REGISTERED.toLocalizedString(new Object[] { other.getClass().getName(), other.getId() }));
}
}
} while (retry);
try {
for (int i = 0; i < classes.length; i++) {
DataSerializer oldS = classesToSerializers.putIfAbsent(classes[i].getName(), s);
if (oldS != null) {
if (!s.equals(oldS)) {
// cleanup the ones we have already added
for (int j = 0; j < i; j++) {
classesToSerializers.remove(classes[j].getName(), s);
}
dsForMarkers = null;
String oldMsg;
if (oldS.getId() == 0) {
oldMsg = "DataSerializer has built-in support for class ";
} else {
oldMsg = "A DataSerializer of class " + oldS.getClass().getName() + " is already registered to support class ";
}
String msg = oldMsg + classes[i].getName() + " so the DataSerializer of class " + s.getClass().getName() + " could not be registered.";
if (oldS.getId() == 0) {
throw new IllegalArgumentException(msg);
} else {
throw new IllegalStateException(msg);
}
}
}
}
} finally {
if (dsForMarkers == null) {
idsToSerializers.remove(idx, m);
} else {
idsToSerializers.replace(idx, m, dsForMarkers);
}
if (oldMarker != null) {
oldMarker.setSerializer(dsForMarkers);
}
m.setSerializer(dsForMarkers);
}
// if dataserializer is getting registered for first time
// its EventID will be null, so generate a new event id
// the the distributed system is connected
InternalCache cache = GemFireCacheImpl.getInstance();
if (cache != null && s.getEventId() == null) {
s.setEventId(new EventID(cache.getDistributedSystem()));
}
if (distribute) {
// send a message to other peers telling them about a newly-registered
// dataserializer, it also send event id of the originator along with the
// dataserializer
sendRegistrationMessage(s);
// send it to cache servers if it is a client
sendRegistrationMessageToServers(s);
}
// send it to all cache clients irrelevant of distribute
// bridge servers send it all the clients irrelevant of
// originator VM
sendRegistrationMessageToClients(s);
fireNewDataSerializer(s);
return s;
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class DistributedRegion method getDistributedLockIfGlobal.
/**
* If this region's scope is GLOBAL, get a distributed lock on the given key, and return the Lock.
* The sender is responsible for unlocking.
*
* @return the acquired Lock if the region is GLOBAL, otherwise null.
*
* @throws NullPointerException if key is null
*/
private Lock getDistributedLockIfGlobal(Object key) throws TimeoutException {
if (getScope().isGlobal()) {
if (isLockingSuspendedByCurrentThread())
return null;
long start = System.currentTimeMillis();
long timeLeft = getCache().getLockTimeout();
long lockTimeout = timeLeft;
StringId msg = null;
Object[] msgArgs = null;
while (timeLeft > 0 || lockTimeout == -1) {
this.cache.getCancelCriterion().checkCancelInProgress(null);
boolean interrupted = Thread.interrupted();
try {
Lock dlock = getDistributedLock(key);
if (!dlock.tryLock(timeLeft, TimeUnit.SECONDS)) {
msg = LocalizedStrings.DistributedRegion_ATTEMPT_TO_ACQUIRE_DISTRIBUTED_LOCK_FOR_0_FAILED_AFTER_WAITING_1_SECONDS;
msgArgs = new Object[] { key, (System.currentTimeMillis() - start) / 1000L };
break;
}
return dlock;
} catch (InterruptedException ex) {
interrupted = true;
this.cache.getCancelCriterion().checkCancelInProgress(ex);
// TODO: Why is it OK to keep going?
if (lockTimeout > -1) {
timeLeft = getCache().getLockTimeout() - (System.currentTimeMillis() - start) / 1000L;
}
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
}
}
// while
if (msg == null) {
msg = LocalizedStrings.DistributedRegion_TIMED_OUT_AFTER_WAITING_0_SECONDS_FOR_THE_DISTRIBUTED_LOCK_FOR_1;
msgArgs = new Object[] { getCache().getLockTimeout(), key };
}
throw new TimeoutException(msg.toLocalizedString(msgArgs));
} else {
return null;
}
}
use of org.apache.geode.i18n.StringId in project geode by apache.
the class PRHARedundancyProvider method insufficientStores.
/**
* Indicate that we are unable to allocate sufficient stores and the timeout period has passed
*
* @param allStores stores we know about
* @param alreadyUsed ones already committed
* @param onlyLog true if only a warning log messages should be generated.
*/
private void insufficientStores(Set allStores, Collection alreadyUsed, boolean onlyLog) {
final String regionStat = regionStatus(this.prRegion, allStores, alreadyUsed, onlyLog);
final char newLine;
if (onlyLog) {
newLine = ' ';
} else {
newLine = '\n';
}
final StringId notEnoughValidNodes;
if (alreadyUsed.isEmpty()) {
notEnoughValidNodes = LocalizedStrings.PRHARRedundancyProvider_UNABLE_TO_FIND_ANY_MEMBERS_TO_HOST_A_BUCKET_IN_THE_PARTITIONED_REGION_0;
} else {
notEnoughValidNodes = LocalizedStrings.PRHARRedundancyProvider_CONFIGURED_REDUNDANCY_LEVEL_COULD_NOT_BE_SATISFIED_0;
}
final Object[] notEnoughValidNodesArgs = new Object[] { PRHARedundancyProvider.INSUFFICIENT_STORES_MSG, newLine + regionStat + newLine };
if (onlyLog) {
logger.warn(LocalizedMessage.create(notEnoughValidNodes, notEnoughValidNodesArgs));
} else {
throw new PartitionedRegionStorageException(notEnoughValidNodes.toLocalizedString(notEnoughValidNodesArgs));
}
}
Aggregations