当前位置: 首页>>代码示例>>Java>>正文


Java HGLiveHandle类代码示例

本文整理汇总了Java中org.hypergraphdb.handle.HGLiveHandle的典型用法代码示例。如果您正苦于以下问题:Java HGLiveHandle类的具体用法?Java HGLiveHandle怎么用?Java HGLiveHandle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HGLiveHandle类属于org.hypergraphdb.handle包,在下文中一共展示了HGLiveHandle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: increment

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
private void increment(final int idx)
{        
    final HGTransactionManager txman = graph.getTransactionManager();
    txman.transact(new Callable<SimpleData>() 
    { 
        public SimpleData call()
        {
            HGPersistentHandle handle = handleMap.get(idx);
            HGLiveHandle lHandle = cache.get(handle);
            SimpleData x = null;
            if (lHandle != null)
                x = (SimpleData)lHandle.getRef();
            if (x == null)
            {
                Integer value = data.get(handle);
                x = new SimpleData(idx, value);
                lHandle = cache.atomRead(handle, x, new HGAtomAttrib());
            }
            SimpleData newBean = x.duplicate();
            newBean.incrementValue();                
            cache.atomRefresh(lHandle, newBean, true);
            data.put(handle, newBean.getValue());
            return newBean;
        }
    });
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:27,代码来源:TxCacheTest.java

示例2: atomRefresh

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public HGLiveHandle atomRefresh(HGLiveHandle handle, Object atom, boolean replace)
{
	LiveHandle existing = liveHandles.get(handle.getPersistent());  	
	if (existing != null)
	{
		atoms.remove(existing.getRef());    		
		existing.setRef(atom);
		atoms.put(atom, existing);		    		
	}
	else
	{
    	LiveHandle lHandle = (LiveHandle)handle;    		
		lHandle.setRef(atom);    		
		insert(lHandle);    		
	}
	return handle;
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:18,代码来源:DefaultAtomCache.java

示例3: 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]);
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:39,代码来源:HyperGraph.java

示例4: getSystemFlags

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public int getSystemFlags(HGHandle handle)
{
    if (!config.isUseSystemAtomAttributes())
        return 0;
    else if (handle instanceof HGLiveHandle)
		if (handle instanceof HGManagedLiveHandle)
			return ((HGManagedLiveHandle)handle).getFlags();
		else
			return 0;
	else
	{
		HGAtomAttrib attribs = this.getAtomAttributes((HGPersistentHandle)handle);
		if (attribs != null)
			return attribs.flags;
		else
			return 0;
	}
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:19,代码来源:HyperGraph.java

示例5: addNode

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
private HGLiveHandle addNode(final Object payload, final HGHandle typeHandle, final byte flags)
{
	return getTransactionManager().ensureTransaction(new Callable<HGLiveHandle>() 
	{ public HGLiveHandle call() {
 	HGAtomType type = typeSystem.getType(typeHandle);
 	HGPersistentHandle pTypeHandle = getPersistentHandle(typeHandle);    	
     HGPersistentHandle valueHandle = TypeUtils.storeValue(HyperGraph.this, payload, type);  
	
     HGPersistentHandle [] layout = new HGPersistentHandle[2];            
     layout[0] = pTypeHandle;
     layout[1] = valueHandle;
     final HGLiveHandle lHandle = atomAdded(store.store(layout), payload, flags);
     if (payload instanceof HGTypeHolder)
     	((HGTypeHolder<HGAtomType>)payload).setAtomType(type);    	        	        	        
     indexByType.addEntry(pTypeHandle, lHandle.getPersistent());
     indexByValue.addEntry(valueHandle, lHandle.getPersistent());
     idx_manager.maybeIndex(pTypeHandle, type, lHandle.getPersistent(), payload);	        
     return lHandle;    
	} });    	
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:21,代码来源:HyperGraph.java

示例6: 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();
	}
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:22,代码来源:HyperGraph.java

示例7: updateLinkLiveHandle

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
/**
 * Update a link to point to a "live" target instead of holding a 
 * persistent handle. This is slightly inefficient as it needs
 * to loop through all targets of the link. It is here perhaps that
 * a distinction b/w ordered and unordered links might become useful
 * for efficiency purposes: an unordered link would be able to use
 * a hash lookup on its handles to find the one that needs to be updated,
 * instead of a linear traversal. On the other, link arities tend to be
 * rather small, usually 2-3, so it shouldn't be a problem. 
 */
void updateLinkLiveHandle(HGLink link, HGLiveHandle lHandle)
{
    int arity = link.getArity();
    for (int i = 0; i < arity; i++)
    {
        HGHandle current = link.getTargetAt(i);
        if (current == lHandle)
            return;
        else if (current.equals(lHandle.getPersistent()))
        {
            link.notifyTargetHandleUpdate(i, lHandle);
            return;
        }
    }
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:26,代码来源:HyperGraph.java

示例8: WeakRefAtomCache

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public WeakRefAtomCache(HyperGraph graph)
{
    this.graph = graph;
    if (graph.getConfig().isTransactional())
    {
        atoms = atomsTx = new TxCacheMap<Object, HGLiveHandle>(
                                    graph.getTransactionManager(), 
                                    WeakIdentityHashMap.class,
                                    null);
        atomsTx.setReturnLatestAvailable(true);
           liveHandles = liveHandlesTx = new TxCacheMap<HGPersistentHandle, WeakHandle>(
                                       graph.getTransactionManager(), 
                                       HashMap.class,
                                       null); 	        
        frozenAtoms = new TxCacheMap<HGLiveHandle, Object>(graph.getTransactionManager(), null, null);
    }
    else
    {
        atoms = new HashCacheMap<Object, HGLiveHandle>(); // need a weak hash cache map?
        liveHandles = new HashCacheMap<HGPersistentHandle, WeakHandle>();
        frozenAtoms = new HashCacheMap<HGLiveHandle, Object>();
    }
	cleanupThread.setPriority(Thread.MAX_PRIORITY);
	cleanupThread.setDaemon(true);		
	cleanupThread.start();
}
 
开发者ID:armatys,项目名称:hypergraphdb-android,代码行数:27,代码来源:WeakRefAtomCache.java

示例9: getStruct

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public Object getStruct(Object value)
{
    if (value instanceof HGPersistentHandle)
        return value.toString();
    else if (value instanceof HGLiveHandle)
        return ((HGLiveHandle) value).getPersistent().toString();
    else
        throw new RuntimeException(
                "Attempt to serialize something that is not a HG handle as a HG handle.");
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:11,代码来源:Structs.java

示例10: resolve

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public IncidenceSet resolve(HGPersistentHandle key)
{
	HGSearchResult<HGPersistentHandle> rs = graph.getStore().getIncidenceResultSet(key);
	try
	{
		int size = keepInMemoryThreshold;
		if (keepInMemoryThreshold < Integer.MAX_VALUE)
			size = rs == HGSearchResult.EMPTY ? 0 : ((CountMe)rs).count();
		if (size <= keepInMemoryThreshold)
		{
			ArrayList<HGPersistentHandle> A = new ArrayList<HGPersistentHandle>();
			while (rs.hasNext())
				A.add(rs.next());
			ArrayBasedSet<HGHandle> impl = new ArrayBasedSet<HGHandle>(A.toArray(HGUtils.EMPTY_HANDLE_ARRAY));
			impl.setLock(new DummyReadWriteLock());
			IncidenceSet result = new IncidenceSet(key,
													new TxCacheSet<HGPersistentHandle, HGHandle>(
															graph.getTransactionManager(),
															impl,
															key,
															loader,
															writeMap));
			HGLiveHandle lHandle = graph.cache.get(key);
			if (lHandle != null)
				graph.updateLinksInIncidenceSet(result, lHandle);
			return result;
		}
		else
			return new IncidenceSet(key, new StorageBasedIncidenceSet(key, graph));
	}
	finally
	{
		rs.close();
	}
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:36,代码来源:ISRefResolver.java

示例11: persistentHandle

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
static HGPersistentHandle persistentHandle(HGHandle h)
{
	if (h instanceof HGPersistentHandle)
		return (HGPersistentHandle)h;
	else
		return ((HGLiveHandle)h).getPersistent();
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:8,代码来源:U.java

示例12: getBytes

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
static byte [] getBytes(HGHandle h)
{
	if (h instanceof HGPersistentHandle)
		return ((HGPersistentHandle)h).toByteArray();
	else
		return ((HGLiveHandle)h).getPersistent().toByteArray();
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:8,代码来源:U.java

示例13: loadPredefinedType

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
HGLiveHandle loadPredefinedType(HGPersistentHandle pHandle)
	{
		graph.getEventManager().dispatch(graph, new HGLoadPredefinedTypeEvent(pHandle));
//		HGLiveHandle result = graph.cache.get(pHandle);
//		if (result != null)
//			return result;
//		else
//		{
			String classname = getPredefinedTypesDB().findFirst(pHandle);
			if (classname == null)
			{
				throw new HGException("Unable to load predefined type with handle " +
				           pHandle +
			              " please review the documentation about predefined types and how to hook them with the HyperGraph type system.");
			}
			try
			{
				Class<?> clazz = loadClass(classname);
				HGAtomType type = (HGAtomType)clazz.newInstance();
				type.setHyperGraph(graph);
				return (HGLiveHandle)addPredefinedType(pHandle, type, (URI)null);
			}
			catch (Throwable ex)
			{
				throw new HGException("Could not create predefined type instance with " +
				                    classname + " for type " + pHandle + ": " + ex.toString(), ex);
			}
//		}
	}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:30,代码来源:HGTypeSystem.java

示例14: setHyperGraph

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public void setHyperGraph(HyperGraph graph) 
{
       this.graph = graph;
       this.closing = false;
       if (graph.getConfig().isTransactional())
       {
           atoms = atomsTx = new TxCacheMap<Object, HGLiveHandle>(
                                       graph.getTransactionManager(), 
                                       WeakIdentityHashMap.class,
                                       null);
           atomsTx.setReturnLatestAvailable(true);
           liveHandles = liveHandlesTx = new TxCacheMap<HGPersistentHandle, WeakHandle>(
                                       graph.getTransactionManager(), 
                                       HashMap.class,
                                       null);          
           frozenAtoms = new TxCacheMap<HGLiveHandle, Object>(graph.getTransactionManager(), null, null);
       }
       else
       {
           atoms = new HashCacheMap<Object, HGLiveHandle>(); // need a weak hash cache map?
           liveHandles = new HashCacheMap<HGPersistentHandle, WeakHandle>();
           frozenAtoms = new HashCacheMap<HGLiveHandle, Object>();
       }
       cleanupThread = new PhantomCleanup();
       cleanupThread.setPriority(Thread.MAX_PRIORITY);
       cleanupThread.setDaemon(true);      
       cleanupThread.start();

	cleanupThread.setName("HGCACHE Cleanup - " + graph.getLocation());
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:31,代码来源:WeakRefAtomCache.java

示例15: get

import org.hypergraphdb.handle.HGLiveHandle; //导入依赖的package包/类
public HGLiveHandle get(HGPersistentHandle pHandle) 
{
    WeakHandle h = liveHandles.get(pHandle);
	if (h != null)
		h.accessed();
	return h;
}
 
开发者ID:hypergraphdb,项目名称:hypergraphdb,代码行数:8,代码来源:WeakRefAtomCache.java


注:本文中的org.hypergraphdb.handle.HGLiveHandle类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。