use of org.apache.geode.i18n.StringId in project geode by apache.
the class Get70 method cmdExecute.
@Override
public void cmdExecute(Message clientMessage, ServerConnection serverConnection, long startparam) throws IOException {
long start = startparam;
Part regionNamePart = null, keyPart = null, valuePart = null;
String regionName = null;
Object callbackArg = null, key = null;
CachedRegionHelper crHelper = serverConnection.getCachedRegionHelper();
CacheServerStats stats = serverConnection.getCacheServerStats();
StringId errMessage = null;
serverConnection.setAsTrue(REQUIRES_RESPONSE);
// requiresResponse = true;
{
long oldStart = start;
start = DistributionStats.getStatTime();
stats.incReadGetRequestTime(start - oldStart);
}
// Retrieve the data from the message parts
int parts = clientMessage.getNumberOfParts();
regionNamePart = clientMessage.getPart(0);
keyPart = clientMessage.getPart(1);
// valuePart = null; (redundant assignment)
if (parts > 2) {
valuePart = clientMessage.getPart(2);
try {
callbackArg = valuePart.getObject();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
// responded = true;
serverConnection.setAsTrue(RESPONDED);
return;
}
}
regionName = regionNamePart.getString();
try {
key = keyPart.getStringOrObject();
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
// responded = true;
serverConnection.setAsTrue(RESPONDED);
return;
}
if (logger.isDebugEnabled()) {
logger.debug("{}: Received 7.0 get request ({} bytes) from {} for region {} key {} txId {}", serverConnection.getName(), clientMessage.getPayloadLength(), serverConnection.getSocketString(), regionName, key, clientMessage.getTransactionId());
}
// Process the get request
if (key == null || regionName == null) {
if ((key == null) && (regionName == null)) {
errMessage = LocalizedStrings.Request_THE_INPUT_REGION_NAME_AND_KEY_FOR_THE_GET_REQUEST_ARE_NULL;
} else if (key == null) {
errMessage = LocalizedStrings.Request_THE_INPUT_KEY_FOR_THE_GET_REQUEST_IS_NULL;
} else if (regionName == null) {
errMessage = LocalizedStrings.Request_THE_INPUT_REGION_NAME_FOR_THE_GET_REQUEST_IS_NULL;
}
String s = errMessage.toLocalizedString();
logger.warn("{}: {}", serverConnection.getName(), s);
writeErrorResponse(clientMessage, MessageType.REQUESTDATAERROR, s, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
Region region = serverConnection.getCache().getRegion(regionName);
if (region == null) {
String reason = LocalizedStrings.Request__0_WAS_NOT_FOUND_DURING_GET_REQUEST.toLocalizedString(regionName);
writeRegionDestroyedEx(clientMessage, regionName, reason, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
GetOperationContext getContext = null;
try {
// for integrated security
this.securityService.authorizeRegionRead(regionName, key.toString());
AuthorizeRequest authzRequest = serverConnection.getAuthzRequest();
if (authzRequest != null) {
getContext = authzRequest.getAuthorize(regionName, key, callbackArg);
callbackArg = getContext.getCallbackArg();
}
} catch (NotAuthorizedException ex) {
writeException(clientMessage, ex, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// Get the value and update the statistics. Do not deserialize
// the value if it is a byte[].
Entry entry;
try {
entry = getEntry(region, key, callbackArg, serverConnection);
} catch (Exception e) {
writeException(clientMessage, e, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
@Retained final Object originalData = entry.value;
Object data = originalData;
try {
boolean isObject = entry.isObject;
VersionTag versionTag = entry.versionTag;
boolean keyNotPresent = entry.keyNotPresent;
try {
AuthorizeRequestPP postAuthzRequest = serverConnection.getPostAuthzRequest();
if (postAuthzRequest != null) {
try {
getContext = postAuthzRequest.getAuthorize(regionName, key, data, isObject, getContext);
GetOperationContextImpl gci = (GetOperationContextImpl) getContext;
Object newData = gci.getRawValue();
if (newData != data) {
// user changed the value
isObject = getContext.isObject();
data = newData;
}
} finally {
if (getContext != null) {
((GetOperationContextImpl) getContext).release();
}
}
}
} catch (NotAuthorizedException ex) {
writeException(clientMessage, ex, false, serverConnection);
serverConnection.setAsTrue(RESPONDED);
return;
}
// post process
data = this.securityService.postProcess(regionName, key, data, entry.isObject);
long oldStart = start;
start = DistributionStats.getStatTime();
stats.incProcessGetTime(start - oldStart);
if (region instanceof PartitionedRegion) {
PartitionedRegion pr = (PartitionedRegion) region;
if (pr.getNetworkHopType() != PartitionedRegion.NETWORK_HOP_NONE) {
writeResponseWithRefreshMetadata(data, callbackArg, clientMessage, isObject, serverConnection, pr, pr.getNetworkHopType(), versionTag, keyNotPresent);
pr.clearNetworkHopData();
} else {
writeResponse(data, callbackArg, clientMessage, isObject, versionTag, keyNotPresent, serverConnection);
}
} else {
writeResponse(data, callbackArg, clientMessage, isObject, versionTag, keyNotPresent, serverConnection);
}
} finally {
OffHeapHelper.release(originalData);
}
serverConnection.setAsTrue(RESPONDED);
if (logger.isDebugEnabled()) {
logger.debug("{}: Wrote get response back to {} for region {} {}", serverConnection.getName(), serverConnection.getSocketString(), regionName, entry);
}
stats.incWriteGetResponseTime(DistributionStats.getStatTime() - start);
}
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 GemFireBasicDataSource method loadDriver.
private void loadDriver() throws SQLException {
try {
Class driverClass = ClassPathLoader.getLatest().forName(jdbcDriver);
driverObject = (Driver) driverClass.newInstance();
} catch (Exception ex) {
StringId msg = LocalizedStrings.GemFireBasicDataSource_AN_EXCEPTION_WAS_CAUGHT_WHILE_TRYING_TO_LOAD_THE_DRIVER;
String msgArg = ex.getLocalizedMessage();
logger.error(LocalizedMessage.create(msg, msgArg), ex);
throw new SQLException(msg.toLocalizedString(msgArg));
}
}
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;
}
Aggregations