Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2010-2015 Pivotal Software, Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you
* may not use this file except in compliance with the License. You
* may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied. See the License for the specific language governing
* permissions and limitations under the License. See accompanying
* LICENSE file.
*/
package com.gemstone.gemfire.pdx.internal;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import com.gemstone.gemfire.InternalGemFireError;
import com.gemstone.gemfire.InternalGemFireException;
import com.gemstone.gemfire.cache.AttributesFactory;
import com.gemstone.gemfire.cache.Cache;
import com.gemstone.gemfire.cache.DataPolicy;
import com.gemstone.gemfire.cache.EntryEvent;
import com.gemstone.gemfire.cache.Operation;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionAttributes;
import com.gemstone.gemfire.cache.RegionExistsException;
import com.gemstone.gemfire.cache.Scope;
import com.gemstone.gemfire.cache.TimeoutException;
import com.gemstone.gemfire.cache.TransactionException;
import com.gemstone.gemfire.cache.client.Pool;
import com.gemstone.gemfire.cache.client.PoolManager;
import com.gemstone.gemfire.cache.client.internal.PoolImpl;
import com.gemstone.gemfire.cache.util.CacheListenerAdapter;
import com.gemstone.gemfire.cache.util.Gateway;
import com.gemstone.gemfire.cache.util.GatewayHub;
import com.gemstone.gemfire.cache.wan.GatewaySender;
import com.gemstone.gemfire.distributed.DistributedLockService;
import com.gemstone.gemfire.distributed.LockServiceDestroyedException;
import com.gemstone.gemfire.distributed.internal.DistributionManager;
import com.gemstone.gemfire.distributed.internal.InternalDistributedSystem;
import com.gemstone.gemfire.distributed.internal.locks.DLockService;
import com.gemstone.gemfire.internal.CopyOnWriteHashSet;
import com.gemstone.gemfire.internal.cache.DiskStoreImpl;
import com.gemstone.gemfire.internal.cache.EntryEventImpl;
import com.gemstone.gemfire.internal.cache.EnumListenerEvent;
import com.gemstone.gemfire.internal.cache.EventID;
import com.gemstone.gemfire.internal.cache.GatewayEventCallbackArgument;
import com.gemstone.gemfire.internal.cache.GatewayImpl;
import com.gemstone.gemfire.internal.cache.GemFireCacheImpl;
import com.gemstone.gemfire.internal.cache.InternalRegionArguments;
import com.gemstone.gemfire.internal.cache.LocalRegion;
import com.gemstone.gemfire.internal.cache.TXManagerImpl;
import com.gemstone.gemfire.internal.cache.TXStateInterface;
import com.gemstone.gemfire.internal.cache.wan.AbstractGatewaySender;
import com.gemstone.gemfire.internal.cache.wan.GatewaySenderEventCallbackArgumentImpl;
import com.gemstone.gemfire.internal.util.concurrent.CopyOnWriteHashMap;
import com.gemstone.gemfire.pdx.JSONFormatter;
import com.gemstone.gemfire.pdx.PdxInitializationException;
/**
* @author dsmith
*
*/
public class PeerTypeRegistration implements TypeRegistration {
/**
*
*/
private static final int MAX_TRANSACTION_FAILURES = 10;
public static final String LOCK_SERVICE_NAME = "__PDX";
/**
* The region name. Public for tests only.
*/
public static final String REGION_NAME = GemFireCacheImpl.gfxdSystem() ? "GFXD_PdxTypes" : "PdxTypes";
public static final String REGION_FULL_PATH = "/" + REGION_NAME;
private int nextTypeId;
private final int maxTypeId;
private int nextEnumId;
private final int maxEnumId;
private volatile DistributedLockService dls;
private final Object dlsLock = new Object();
private final GemFireCacheImpl cache;
/**
* The region where the PDX metadata is stored.
* Because this region is transactional for our internal updates
* but we don't want to participate in the users transactions,
* all operations on this region must suspend any existing
* transactions with suspendTX/resumeTX.
*/
private Region idToType;
/** This map serves two purposes. It lets us look
* up an id based on a type, if we previously found that type
* in the region. And, if a type is present in this map, that means
* we read the type while holding the dlock, which means the type
* was distributed to all members.
*/
private final Map typeToId = Collections.synchronizedMap(new HashMap());
private final Map enumToId = Collections.synchronizedMap(new HashMap());
private final Map> classToType = new CopyOnWriteHashMap>();
private volatile boolean typeRegistryInUse = false;
public PeerTypeRegistration(GemFireCacheImpl cache) {
this.cache = cache;
int distributedSystemId = cache.getDistributedSystem().getDistributionManager().getDistributedSystemId();
if(distributedSystemId == -1) {
distributedSystemId = 0;
}
this.nextTypeId = distributedSystemId << 24;
this.maxTypeId = distributedSystemId << 24 | 0xFFFFFF;
this.nextEnumId = distributedSystemId << 24;
this.maxEnumId = distributedSystemId << 24 | 0xFFFFFF;
}
private Region getIdToType() {
if (this.idToType != null) {
return this.idToType;
} else {
if (this.cache.getPdxPersistent()
&& this.cache.getCacheConfig().pdxDiskStoreUserSet) {
throw new PdxInitializationException("PDX registry could not be initialized because the disk store " + this.cache.getPdxDiskStore() + " was not created.");
} else {
throw new PdxInitializationException("PDX registry was not initialized.");
}
}
}
public void initialize() {
AttributesFactory