/** * This method nulls the TCObject reference in the cloned object if the clone() method had done a shallow copy. This * is called from the instrumented code. * * @param original Original object * @param clone Clone of original * @return Clone, modified */ public static Object fixTCObjectReferenceOfClonedObject(Object original, Object clone) { if (clone instanceof Manageable && original instanceof Manageable) { Manageable mClone = (Manageable) clone; Manageable mOriginal = (Manageable) original; if (mClone.__tc_managed() != null && clone != original && mClone.__tc_managed() == mOriginal.__tc_managed()) { // A shallow copy is returned. We don't want the clone to have the same TCObject mClone.__tc_managed(null); } } return clone; }
@Override public <K> Map<K, Set<DsoNode>> getNodesWithKeys(final Map<K, ?> map, final Collection<? extends K> keys) { Assert.assertNotNull(clusterMetaDataManager); if (null == keys || 0 == keys.size() || null == map) { return Collections.emptyMap(); } Map<K, Set<DsoNode>> result = new HashMap<K, Set<DsoNode>>(); if (map instanceof Manageable) { Manageable manageable = (Manageable) map; if (manageable.__tc_isManaged()) { Map<K, Set<NodeID>> rawResult = null; if (manageable instanceof TCMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCMap) map, keys); } else if (manageable instanceof TCServerMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCServerMap) map, keys); } if (rawResult != null) { for (Map.Entry<K, Set<NodeID>> entry : rawResult.entrySet()) { Set<DsoNode> dsoNodes = new HashSet<DsoNode>(rawResult.entrySet().size(), 1.0f); for (NodeID nodeID : entry.getValue()) { DsoNodeInternal dsoNode = topology.getAndRegisterDsoNode((ClientID) nodeID); dsoNodes.add(dsoNode); } result.put(entry.getKey(), dsoNodes); } } } } return result; }
@Override public <K> Map<K, Set<DsoNode>> getNodesWithKeys(final Map<K, ?> map, final Collection<? extends K> keys) { Assert.assertNotNull(clusterMetaDataManager); if (null == keys || 0 == keys.size() || null == map) { return Collections.emptyMap(); } Map<K, Set<DsoNode>> result = new HashMap<K, Set<DsoNode>>(); if (map instanceof Manageable) { Manageable manageable = (Manageable) map; if (manageable.__tc_isManaged()) { Map<K, Set<NodeID>> rawResult = null; if (manageable instanceof TCMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCMap) map, keys); } else if (manageable instanceof TCServerMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCServerMap) map, keys); } if (rawResult != null) { for (Map.Entry<K, Set<NodeID>> entry : rawResult.entrySet()) { Set<DsoNode> dsoNodes = new HashSet<DsoNode>(rawResult.entrySet().size(), 1.0f); for (NodeID nodeID : entry.getValue()) { DsoNodeInternal dsoNode = topology.getAndRegisterDsoNode((ClientID) nodeID); dsoNodes.add(dsoNode); } result.put(entry.getKey(), dsoNodes); } } } } return result; }
@Override public TCObject lookupOrCreate(final Object obj, GroupID gid) { if (obj instanceof Manageable) { TCObject tco = ((Manageable) obj).__tc_managed(); if (tco != null) { return tco; } } return this.objectManager.lookupOrCreate(obj, gid); }
@Override public <K> Map<K, Set<DsoNode>> getNodesWithKeys(final Map<K, ?> map, final Collection<? extends K> keys) throws UnclusteredObjectException { Assert.assertNotNull(clusterMetaDataManager); if (null == keys || 0 == keys.size() || null == map) { return Collections.emptyMap(); } Map<K, Set<DsoNode>> result = new HashMap<K, Set<DsoNode>>(); if (map instanceof Manageable) { Manageable manageable = (Manageable) map; if (manageable.__tc_isManaged()) { Map<K, Set<NodeID>> rawResult = null; if (manageable instanceof TCMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCMap) map, keys); } else if (manageable instanceof TCServerMap) { rawResult = clusterMetaDataManager.getNodesWithKeys((TCServerMap) map, keys); } if (rawResult != null) { for (Map.Entry<K, Set<NodeID>> entry : rawResult.entrySet()) { Set<DsoNode> dsoNodes = new HashSet<DsoNode>(rawResult.entrySet().size(), 1.0f); for (NodeID nodeID : entry.getValue()) { DsoNodeInternal dsoNode = topology.getAndRegisterDsoNode((ClientID) nodeID); dsoNodes.add(dsoNode); } result.put(entry.getKey(), dsoNodes); } } } } return result; }
@Override public TCObject lookupOrCreate(final Object obj, GroupID gid) { if (obj instanceof Manageable) { TCObject tco = ((Manageable) obj).__tc_managed(); if (tco != null) { return tco; } } return this.objectManager.lookupOrCreate(obj, gid); }
@Override public void deserialize(ObjectInput in) throws IOException { this.version = in.readLong(); ObjectID newId = new ObjectID(in.readLong()); if (oid != null) { throw new AssertionError("Old oid=" + oid + " id=" + newId); } this.oid = newId; // Assuming isNew to be false this.isNew = false; if (this instanceof Manageable) { ((Manageable) this).__tc_managed(this); } }
@Override public void deserialize(ObjectInput in) throws IOException { this.version = in.readLong(); ObjectID newId = new ObjectID(in.readLong()); if (oid != null) { throw new AssertionError("Old oid=" + oid + " id=" + newId); } this.oid = newId; // Assuming isNew to be false this.isNew = false; if (this instanceof Manageable) { ((Manageable) this).__tc_managed(this); } }
@Override public TCObject lookupOrCreate(final Object obj, GroupID gid) { if (obj instanceof Manageable) { TCObject tco = ((Manageable) obj).__tc_managed(); if (tco != null) { return tco; } } return this.objectManager.lookupOrCreate(obj, gid); }
@Override public TCObject lookupOrCreate(final Object obj) { if (obj instanceof Manageable) { TCObject tco = ((Manageable) obj).__tc_managed(); if (tco != null) { return tco; } } return this.objectManager.lookupOrCreate(obj); }
@Override public TCObject lookupOrCreate(final Object obj) { if (obj instanceof Manageable) { TCObject tco = ((Manageable) obj).__tc_managed(); if (tco != null) { return tco; } } return this.objectManager.lookupOrCreate(obj); }
@Override public void deserialize(ObjectInput in) throws IOException { this.version = in.readLong(); ObjectID newId = new ObjectID(in.readLong()); if (oid != null) { throw new AssertionError("Old oid=" + oid + " id=" + newId); } this.oid = newId; // Assuming isNew to be false this.isNew = false; if (this instanceof Manageable) { ((Manageable) this).__tc_managed(this); } }
private TCObject basicLookup(final Object obj) { if (obj == null) { return null; } if (obj instanceof TCObjectSelf) { TCObjectSelf self = (TCObjectSelf) obj; if (self.isInitialized()) { return self; } else { // return null when not initialized yet, as __tc_managed() is itself and not null return null; } } if (obj instanceof Manageable) { return ((Manageable) obj).__tc_managed(); } return this.pojoToManaged.get(obj); }
private TCObject basicLookup(final Object obj) { if (obj == null) { return null; } if (obj instanceof TCObjectSelf) { TCObjectSelf self = (TCObjectSelf) obj; if (self.isInitialized()) { return self; } else { // return null when not initialized yet, as __tc_managed() is itself and not null return null; } } if (obj instanceof Manageable) { return ((Manageable) obj).__tc_managed(); } return this.pojoToManaged.get(obj); }
private TCObject basicLookup(final Object obj) { if (obj == null) { return null; } if (obj instanceof TCObjectSelf) { TCObjectSelf self = (TCObjectSelf) obj; if (self.isInitialized()) { return self; } else { // return null when not initialized yet, as __tc_managed() is itself and not null return null; } } if (obj instanceof Manageable) { return ((Manageable) obj).__tc_managed(); } return this.pojoToManaged.get(obj); }
private String getInstanceDsoLockName() { if (instanceDsoLockName != null) { return instanceDsoLockName; } instanceDsoLockName = "@" + getClass().getSimpleName() + ":" + ((Manageable) this).__tc_managed().getObjectID().toLong(); return instanceDsoLockName; }
@Override public TCObject lookupExistingOrNull(final Object pojo) { if (pojo == null) { return null; } if (pojo instanceof Manageable) { return ((Manageable) pojo).__tc_managed(); } try { return this.objectManager.lookupExistingOrNull(pojo); } catch (final Throwable t) { Util.printLogAndRethrowError(t, logger); // shouldn't get here throw new AssertionError(); } }
@Override public TCObject lookupExistingOrNull(final Object pojo) { if (pojo == null) { return null; } if (pojo instanceof Manageable) { return ((Manageable) pojo).__tc_managed(); } try { return this.objectManager.lookupExistingOrNull(pojo); } catch (final Throwable t) { Util.printLogAndRethrowError(t, logger); // shouldn't get here throw new AssertionError(); } }
@Override public TCObject lookupExistingOrNull(final Object pojo) { if (pojo == null) { return null; } if (pojo instanceof Manageable) { return ((Manageable) pojo).__tc_managed(); } try { return this.objectManager.lookupExistingOrNull(pojo); } catch (final Throwable t) { Util.printLogAndRethrowError(t, logger); // shouldn't get here throw new AssertionError(); } }
private Object getPortableKey(final Object key) { Object portableKey = key; if (key instanceof Manageable) { final TCObject keyObject = ((Manageable) key).__tc_managed(); if (keyObject == null) { throw new UnsupportedOperationException( "Key is portable, but not shared. This is currently not supported with TCObjectServerMap. Key = " + key); } portableKey = keyObject.getObjectID(); } if (!LiteralValues.isLiteralInstance(portableKey)) { // formatter throw new UnsupportedOperationException( "Key is not portable. It needs to be a liternal or portable and shared for TCObjectServerMap. Key = " + portableKey); } return portableKey; }