本文整理匯總了Java中org.hypergraphdb.handle.HGLiveHandle.getRef方法的典型用法代碼示例。如果您正苦於以下問題:Java HGLiveHandle.getRef方法的具體用法?Java HGLiveHandle.getRef怎麽用?Java HGLiveHandle.getRef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.hypergraphdb.handle.HGLiveHandle
的用法示例。
在下文中一共展示了HGLiveHandle.getRef方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getType
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
/**
* <p>Retrieve the handle of the type of the atom referred to by <code>handle</code>.</p>
*
* <p><strong>FIXME:</strong> Instances of the same run-time Java type are not guaranteed
* to have the same HyperGraph type. For instance, a Java <code>String</code> may be mapped
* either to a HyperGraph indexed and reference counted strings, or to long text blobs. Therefore,
* the correct way of getting the actual HG type of an atom is by reading of off storage. We
* don't cache type handles of atoms as of now and this might turn out to be a performance issue.
* </p.
*
* @param handle The <code>HGHandle</code> of the atom whose type is desired.
* @return The <code>HGHandle</code> of the atom type.
* @throws HGException if the passed in handle is invalid or unknown to HyperGraph.
*/
public HGHandle getType(HGHandle handle)
{
HGPersistentHandle pHandle;
Object atom = null;
if (handle instanceof HGLiveHandle)
{
atom = ((HGLiveHandle)handle).getRef();
pHandle = ((HGLiveHandle)handle).getPersistent();
}
else
{
pHandle = (HGPersistentHandle)handle;
HGLiveHandle lHandle = cache.get(pHandle);
if (lHandle != null)
atom = lHandle.getRef();
}
if (atom != null && atom instanceof HGTypeHolder)
return getHandle(((HGTypeHolder)atom).getAtomType());
HGPersistentHandle [] link = store.getLink(pHandle);
if (link == null || link.length < 2)
return null;
else
return refreshHandle(link[0]);
}
示例2: updateLinksInIncidenceSet
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
void updateLinksInIncidenceSet(IncidenceSet incidenceSet, HGLiveHandle liveHandle)
{
HGSearchResult<HGHandle> rs = incidenceSet.getSearchResult();
try
{
while (rs.hasNext())
{
HGLiveHandle lh = cache.get((HGPersistentHandle)rs.next());
if (lh != null)
{
HGLink incidenceLink = (HGLink)lh.getRef();
if (incidenceLink != null) // ref may be null because of cache eviction
updateLinkLiveHandle(incidenceLink, liveHandle);
}
}
}
finally
{
rs.close();
}
}
示例3: freeze
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
public void freeze(HGLiveHandle handle)
{
Object atom = handle.getRef();
if (atom != null)
{
if (graph.getTransactionManager().getContext().getCurrent().isReadOnly())
frozenAtoms.load(handle, atom);
else
frozenAtoms.put(handle, atom);
}
}
示例4: freeze
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
public void freeze(HGLiveHandle handle)
{
Object atom = handle.getRef();
if (atom != null)
synchronized (frozenAtoms)
{
frozenAtoms.put(handle, atom);
}
}
示例5: refreshHandle
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
/**
* <p>
* Refresh an atom handle with a currently valid and efficient run-time value. HyperGraph
* manages essentially two types of handles: run-time handles that are reminiscent to memory
* pointers and provide very fast access to loaded atoms and persistent handles that refer
* to long term storage. An atom can be accessed with both types of handles at all times
* regardless of whether it is currently in memory or "passified" into permanent storage.
* During long operations on a large graph, it is likely that atoms get moved in and out
* of main memory and their <em>live</em> status constantly fluctuates. This method allows
* you to bring a <code>HGHandle</code> in line with the current <em>live</em> status of
* an atom. It is desirable to bring a <code>HGHandle</code> when the atom will be accessed
* frequently. The following scenarios describe situation where it may be worth refreshing
* a handle:
* </p>
*
* <ul>
* <li>A link has been retrieved and the atoms in its target set will be frequently
* accessed. Generally, the atom handles comprising the target set will be persistent handles,
* unless those atoms are loaded at the time the link is retrieved. Therefore, one may
* want to refresh that target handles after their corresponding atoms have been loaded
* in memory.</li>
* <li>An atom was loaded, but it wasn't used for a long time and was therefore removed
* from the cache. In this case, its live handle would loose its "liveliness" and it would
* be a good idea to refresh it if the atom starts being used again.
* </ul>
*
* <p>
* Given a persistent handle as an argument, this method will return the corresponding live handle
* if and only if the atom currently loaded. Given an invalid live handle, the method will
* either return a new, valid one if the atom was re-loaded, or it will simply return
* its argument if the atom is currently in the cache.
* </p>
*
* @param handle The handle of the atom.
* @return An updated handle according to the behavior described above.
*/
public HGHandle refreshHandle(HGHandle handle)
{
if (handle instanceof HGPersistentHandle)
{
HGHandle result = cache.get((HGPersistentHandle)handle);
return result != null ? result : handle;
}
else
{
HGLiveHandle live = (HGLiveHandle)handle;
if (live.getRef() == null)
{
HGLiveHandle updated = cache.get(live.getPersistent());
if (updated != null)
return updated;
else
return live.getPersistent();
}
else
return handle;
}
}
示例6: morph
import org.hypergraphdb.handle.HGLiveHandle; //導入方法依賴的package包/類
/**
* Change the type value of an atom value. It is assumed that oldType and newType keep
* the same handle. This is used when we are replacing the value of a type atom with another
* value (which must be a compatible type value). Morphing can potentially lead to a
* different run-time instance of the atom. So, if the atom is "alive", we replace the
* run-time instance.
*
* @param instanceHandle The atom
* @param oldType the old type instance
* @param newType the new type instance
*/
private void morph(HGPersistentHandle instanceHandle, HGAtomType oldType, HGAtomType newType)
{
HGPersistentHandle [] layout = store.getLink(instanceHandle);
Object oldInstance = rawMake(layout, oldType, instanceHandle);
TypeUtils.releaseValue(this, oldType, layout[1]);
//2012.08.07 hilpold already called in previous method: oldType.release(layout[1]);
indexByValue.removeEntry(layout[1], instanceHandle);
layout[1] = TypeUtils.storeValue(this, oldInstance, newType);
indexByValue.addEntry(layout[1], instanceHandle);
store.store(instanceHandle, layout);
Object newInstance = rawMake(layout, newType, instanceHandle);
HGLiveHandle instanceLiveHandle = cache.get(instanceHandle);
if (instanceLiveHandle != null && instanceLiveHandle.getRef() != null)
cache.atomRefresh(instanceLiveHandle, newInstance, true);
if (oldInstance instanceof HGAtomType)
{
HGSearchResult<HGPersistentHandle> rs = null;
try
{
rs = indexByType.find(instanceHandle);
if (rs.hasNext() && ! (newInstance instanceof HGAtomType))
throw new HGException("Cannot replace value of atom " + instanceHandle +
" which was a type with something that is not a type");
oldType = (HGAtomType)oldInstance;
newType = (HGAtomType)newInstance;
while (rs.hasNext())
{
morph((HGPersistentHandle)rs.next(), oldType, newType);
}
}
finally
{
if (rs != null) rs.close();
}
}
// if newInstance is a type, but not oldInstance, we're ok...
}