com.gemstone.gemfire.internal.cache.ha.HAContainerRegion Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of gemfire-core Show documentation
Show all versions of gemfire-core Show documentation
SnappyData store based off Pivotal GemFireXD
The newest version!
/*
* 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.internal.cache.ha;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import com.gemstone.gemfire.CancelException;
import com.gemstone.gemfire.cache.EntryDestroyedException;
import com.gemstone.gemfire.cache.Region;
import com.gemstone.gemfire.cache.RegionDestroyedException;
import com.gemstone.gemfire.internal.cache.tier.sockets.CacheClientProxy;
import com.gemstone.gemfire.internal.cache.tier.sockets.ClientProxyMembershipID;
import com.gemstone.gemfire.internal.cache.tier.sockets.ClientUpdateMessageImpl;
import com.gemstone.gemfire.internal.cache.tier.sockets.HAEventWrapper;
/**
* @author ashetkar
* @since 5.7
*/
public class HAContainerRegion implements HAContainerWrapper {
private Map map;
private final Map haRegionNameToProxy;
public HAContainerRegion (Region region) {
map = region;
haRegionNameToProxy = new ConcurrentHashMap();
}
public ClientProxyMembershipID getProxyID(String haRegionName) {
CacheClientProxy proxy = haRegionNameToProxy.get(haRegionName);
if (proxy != null){
return proxy.getProxyID();
} else {
return null;
}
}
public Object putProxy(String haName, CacheClientProxy proxy) {
return haRegionNameToProxy.put(haName, proxy);
}
public CacheClientProxy getProxy(String haName) {
return haRegionNameToProxy.get(haName);
}
public Object removeProxy(String haName) {
return haRegionNameToProxy.remove(haName);
}
public Object getKey(Object key) {
Map.Entry entry = ((Region)map).getEntry(key);
if(entry != null) {
try {
return entry.getKey();
}
// Is this catch block needed?
catch (EntryDestroyedException ede) {
return null;
}
}
else {
return null;
}
}
public String getName() {
return ((Region)map).getName();
}
public void cleanUp() {
try {
((Region)map).destroyRegion();
}
catch (CancelException e) {
// ignore
}
catch (RegionDestroyedException e) {
// ignore
}
}
public void clear() {
map.clear();
}
public boolean containsKey(Object key) {
return map.containsKey(key);
}
public boolean containsValue(Object value) {
return map.containsValue(value);
}
public Set entrySet() {
return map.entrySet();
}
public Object get(Object key) {
ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl)map.get(key);
if (cum != null) {
cum.setEventIdentifier(((HAEventWrapper)key).getEventId());
if (cum.hasCqs()) {
cum.setClientCqs(((HAEventWrapper)key).getClientCqs());
}
}
return cum;
}
public Object getEntry(Object key) {
Region.Entry entry = ((Region)map).getEntry(key);
if(entry != null) {
ClientUpdateMessageImpl cum = (ClientUpdateMessageImpl)entry.getValue();
cum.setEventIdentifier(((HAEventWrapper)key).getEventId());
if(cum.hasCqs()) {
cum.setClientCqs(((HAEventWrapper)key).getClientCqs());
}
}
return entry;
}
public boolean isEmpty() {
return map.isEmpty();
}
public Set keySet() {
return map.keySet();
}
public Object put(Object key, Object value) {
return map.put(key, value);
}
public void putAll(Map t) {
map.putAll(t);
}
public Object remove(Object key) {
return map.remove(key);
}
public int size() {
return map.size();
}
public Collection values() {
return map.values();
}
}