bugged
stringlengths
6
599k
fixed
stringlengths
10
599k
__index_level_0__
int64
0
1.13M
public SoftReferenceObjectPool(PoolableObjectFactory factory) { _pool = new ArrayList(); _factory = factory; }
public SoftReferenceObjectPool() { _pool = new ArrayList(); _factory = factory; }
1,125,363
public SoftReferenceObjectPool(PoolableObjectFactory factory) { _pool = new ArrayList(); _factory = factory; }
public SoftReferenceObjectPool(PoolableObjectFactory factory) { _pool = new ArrayList(); _factory = null; }
1,125,364
int getNumActive() throws UnsupportedOperationException;
int getNumActive(Object key) throws UnsupportedOperationException;
1,125,365
int getNumIdle() throws UnsupportedOperationException;
int getNumIdle(Object key) throws UnsupportedOperationException;
1,125,366
public static ObjectPool adapt(final KeyedObjectPool keyedPool) throws IllegalArgumentException { return adapt(keyedPool, new Object()); }
public static ObjectPool adapt(final KeyedObjectPool keyedPool) throws IllegalArgumentException { return adapt(keyedPool, new Object()); }
1,125,367
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
1,125,368
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
1,125,369
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new KeyedObjectPoolMinIdleTimerTask(keyedPool, key, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
public static TimerTask checkMinIdle(final KeyedObjectPool keyedPool, final Object key, final int minIdle, final long period) throws IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } if (minIdle < 0) { throw new IllegalArgumentException("minIdle must be non-negative."); } final TimerTask task = new ObjectPoolMinIdleTimerTask(pool, minIdle); getMinIdleTimer().schedule(task, 0L, period); return task; }
1,125,370
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
public GenericKeyedObjectPool(KeyedPoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
1,125,371
public GenericObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
public GenericObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
1,125,372
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedKeyedObjectPool(keyedPool, type); }
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedKeyedObjectPool(keyedPool, type); }
1,125,373
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedKeyedObjectPool(keyedPool, type); }
public static KeyedObjectPool checkedPool(final KeyedObjectPool keyedPool, final Class type) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (type == null) { throw new IllegalArgumentException("type must not be null."); } return new CheckedObjectPool(pool, type); }
1,125,374
public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool) { return erodingPool(keyedPool, 1f); }
public static KeyedObjectPool erodingPool(final KeyedObjectPool keyedPool) { return erodingPool(keyedPool, 1f); }
1,125,375
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { keyedPool.addObject(key); } }
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { keyedPool.addObject(key); } }
1,125,376
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { keyedPool.addObject(key); } }
public static void prefill(final KeyedObjectPool keyedPool, final Object key, final int count) throws Exception, IllegalArgumentException { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } if (key == null) { throw new IllegalArgumentException("key must not be null."); } for (int i = 0; i < count; i++) { pool.addObject(); } }
1,125,377
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
1,125,378
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
public static KeyedObjectPool synchronizedPool(final KeyedObjectPool keyedPool) { if (keyedPool == null) { throw new IllegalArgumentException("keyedPool must not be null."); } assert !(keyedPool instanceof GenericKeyedObjectPool) : "GenericKeyedObjectPool is already thread-safe"; assert !(keyedPool instanceof StackKeyedObjectPool) : "StackKeyedObjectPool is already thread-safe"; assert !"org.apache.commons.pool.composite.CompositeKeyedObjectPool".equals(keyedPool.getClass().getName()) : "CompositeKeyedObjectPools are already thread-safe"; return new SynchronizedKeyedObjectPool(keyedPool); }
1,125,379
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(final KeyedPoolableObjectFactory keyedFactory) { return new SynchronizedKeyedPoolableObjectFactory(keyedFactory); }
public static KeyedPoolableObjectFactory synchronizedPoolableFactory(final KeyedPoolableObjectFactory keyedFactory) { return new SynchronizedKeyedPoolableObjectFactory(keyedFactory); }
1,125,380
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max) { this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY); }
public StackKeyedObjectPool(KeyedPoolableObjectFactory factory, int max) { this(factory,max,DEFAULT_INIT_SLEEPING_CAPACITY); }
1,125,382
public int getNumActive(Object key) { try { return ((Integer)_activeCount.get(key)).intValue(); } catch(NoSuchElementException e) { return 0; } catch(NullPointerException e) { return 0; } }
public int getNumActive(Object key) { try { return ((Integer)_activeCount.get(key)).intValue(); } catch(NoSuchElementException e) { return 0; } catch(NullPointerException e) { return 0; } }
1,125,383
public synchronized int getNumIdle(Object key) { try { return((Stack)(_pools.get(key))).size(); } catch(Exception e) { return 0; } }
public synchronized int getNumIdle(Object key) { try { return((Stack)(_pools.get(key))).size(); } catch(Exception e) { return 0; } }
1,125,384
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,385
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,386
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,387
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,388
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,389
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { continue; } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,390
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,391
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } _numActive++; return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } return pair.value; } catch (Exception e) { try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } else { continue; // keep looping } } } }
1,125,392
public Object borrowObject() throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; synchronized(this) { assertOpen(); // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive <= 0 || _numActive < _maxActive) { // allow new object to be created } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: // allow new object to be created break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _numActive++; } // end synchronized // create new object when needed if(null == pair) { try { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } catch (Exception e) { // object cannot be created synchronized(this) { _numActive--; notifyAll(); } throw e; } } // activate & validate the object try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } return pair.value; } catch (Exception e) { // object cannot be activated or is invalid synchronized(this) { _numActive--; notifyAll(); } try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage()); } else { continue; // keep looping } } } }
public Object borrowObject() throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; synchronized(this) { assertOpen(); // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive < 0 || _numActive < _maxActive) { // allow new object to be created } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: // allow new object to be created break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _numActive++; } // end synchronized // create new object when needed if(null == pair) { try { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } catch (Exception e) { // object cannot be created synchronized(this) { _numActive--; notifyAll(); } throw e; } } // activate & validate the object try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("validateObject failed"); } return pair.value; } catch (Exception e) { // object cannot be activated or is invalid synchronized(this) { _numActive--; notifyAll(); } try { _factory.destroyObject(pair.value); } catch (Exception e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage()); } else { continue; // keep looping } } } }
1,125,394
public abstract Object makeObject();
public abstract Object makeObject() throws Exception;
1,125,395
public StackObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY); }
public StackObjectPool(PoolableObjectFactory factory) { this(factory,DEFAULT_MAX_SLEEPING,DEFAULT_INIT_SLEEPING_CAPACITY); }
1,125,397
public MethodCall(final String name, final Object param) { this(name, Collections.singletonList(param)); }
public MethodCall(final String name, final Object param) { this(name, Collections.singletonList(param)); }
1,125,398
public TestObjectPoolFactory(final String name) { super(name); }
protected TestObjectPoolFactory(final String name) { super(name); }
1,125,399
protected ObjectPoolFactory makeFactory(PoolableObjectFactory objectFactory) throws UnsupportedOperationException { throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
protected ObjectPoolFactory makeFactory(PoolableObjectFactory objectFactory) throws UnsupportedOperationException { throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
1,125,400
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } notifyAll(); // _numActive has changed }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } notifyAll(); // _numActive has changed }
1,125,401
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } notifyAll(); // _numActive has changed }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } notifyAll(); // _numActive has changed }
1,125,402
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } notifyAll(); // _numActive has changed }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) { try { _factory.passivateObject(obj); } catch(Exception e) { ; // ignored, we're throwing it out anway } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj); } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if((_maxIdle > 0) && (_pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { _pool.addFirst(new ObjectTimestampPair(obj)); } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { } } // _numActive has changed }
1,125,403
public synchronized int getNumIdle(Object key) { try { return((LinkedList)(_poolMap.get(key))).size(); } catch(Exception e) { return 0; } }
public synchronized int getNumIdle(Object key) { try { return((LinkedList)(_poolMap.get(key))).size(); } catch(Exception e) { return 0; } }
1,125,404
public synchronized int getNumActive(Object key) { return getActiveCount(key); }
public synchronized int getNumActive(Object key) { return getActiveCount(key); }
1,125,405
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clearOldest(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive <= 0 || active < _maxActive) && (_maxTotal <= 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } }
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clearOldest(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive <= 0 || active < _maxActive) && (_maxTotal <= 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } }
1,125,407
public int getNumActive() throws UnsupportedOperationException { return -1; }
public int getNumActive(Object key) throws UnsupportedOperationException { return -1; }
1,125,408
public int getNumIdle() throws UnsupportedOperationException { return -1; }
public int getNumIdle(Object key) throws UnsupportedOperationException { return -1; }
1,125,409
public void activateObject(Object obj) { }
public void activateObject(Object obj) throws Exception { }
1,125,410
public void destroyObject(Object obj) { }
public void destroyObject(Object obj) throws Exception { }
1,125,411
public void passivateObject(Object obj) { }
public void passivateObject(Object obj) throws Exception { }
1,125,412
protected TestObjectPoolFactory(final String name) { super(name); }
public TestObjectPoolFactory(final String name) { super(name); }
1,125,413
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(_testOnReturn && !(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if((_maxIdle > 0) && (_pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { _pool.addFirst(new ObjectTimestampPair(obj)); } notifyAll(); // _numActive has changed } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(_testOnReturn && !(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { _pool.addFirst(new ObjectTimestampPair(obj)); } notifyAll(); // _numActive has changed } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
1,125,414
public boolean validateObject(Object key, Object obj) { return true; }
public boolean validateObject(Object key, Object obj) { return valid; }
1,125,415
IdentityKey(final int ident) { this.ident = ident; }
IdentityKey(final int ident) { this.ident = ident; }
1,125,416
public ObjectPool createPool() { return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle); }
public ObjectPool createPool() { return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis); }
1,125,417
protected TestKeyedObjectPoolFactory(final String name) { super(name); }
public TestKeyedObjectPoolFactory(final String name) { super(name); }
1,125,418
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
1,125,419
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
1,125,420
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
1,125,421
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
1,125,422
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
private void analyseSubGraphs() { boolean foundStartGraph = false; for ( Iterator iter = _graphList.iterator(); iter.hasNext(); ) { SparseGraph g = (SparseGraph) iter.next(); Object[] vertices = g.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex v = (DirectedSparseVertex)vertices[ i ]; // Find all vertices that are start nodes (START_NODE) if ( v.getUserDatum( LABEL_KEY ).equals( START_NODE ) ) { Object[] edges = v.getOutEdges().toArray(); if ( edges.length != 1 ) { throw new RuntimeException( "A start nod can only have one out edge, look in file: " + g.getUserDatum( FILE_KEY ) ); } DirectedSparseEdge edge = (DirectedSparseEdge)edges[ 0 ]; g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED ); if ( edge.containsUserDatumKey( LABEL_KEY ) ) { if ( foundStartGraph == true ) { throw new RuntimeException( "A start nod can only exist in one file, see files " + _graph.getUserDatum( FILE_KEY )+ ", and " + g.getUserDatum( FILE_KEY ) ); } foundStartGraph = true; _graph = g; } else { // Since the edge does not contain a label, this is a subgraph // Mark the destination node of the edge to a subgraph starting node edge.getDest().addUserDatum( SUBGRAPH_START_VERTEX, SUBGRAPH_START_VERTEX, UserData.SHARED ); } } } } _logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) ); for ( int i = 0; i < _graphList.size(); i++ ) { SparseGraph g = (SparseGraph)_graphList.elementAt( i ); _logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { _logger.debug( " Graphs are the same, next..." ); continue; } Object[] vertices = _graph.getVertices().toArray(); for ( int j = 0; j < vertices.length; j++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)vertices[ j ]; _logger.debug( "Investigating vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) ); if ( v1.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) ) { if ( v1.containsUserDatumKey( MERGE ) ) { _logger.debug( "The vertex is marked MERGE, and will not be replaced by a subgraph."); continue; } if ( v1.containsUserDatumKey( NO_MERGE ) ) { _logger.debug( "The vertex is marked NO_MERGE, and will not be replaced by a subgraph."); continue; } _logger.debug( "A subgraph'ed vertex: " + v1.getUserDatum( LABEL_KEY ) + " in graph: " + g.getUserDatum( FILE_KEY ) + ", equals a node in the graph in file: " + _graph.getUserDatum( FILE_KEY ) ); appendGraph( _graph, g ); //writeGraph("/tmp/debug_append.graphml"); copySubGraphs( _graph, v1 ); //writeGraph("/tmp/debug_merge.graphml"); vertices = _graph.getVertices().toArray(); i = -1; j = -1; } } } // Merge all nodes marked MERGE Object[] list1 = _graph.getVertices().toArray(); for ( int i = 0; i < list1.length; i++ ) { DirectedSparseVertex v1 = (DirectedSparseVertex)list1[ i ]; if ( v1.containsUserDatumKey( MERGE ) == false ) { continue; } Object[] list2 = _graph.getVertices().toArray(); for ( int j = 0; j < list2.length; j++ ) { DirectedSparseVertex v2 = (DirectedSparseVertex)list2[ j ]; if ( v1.hashCode() == v2.hashCode() ) { continue; } if ( v1.getUserDatum( LABEL_KEY ).equals( v2.getUserDatum( LABEL_KEY ) ) == false ) { continue; } _logger.debug( "Merging vertex(" + v1.hashCode() + "): " + v1.getUserDatum( LABEL_KEY ) + "with vertex(" + v2.hashCode() ); Object[] inEdges = v1.getInEdges().toArray(); for (int x = 0; x < inEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)inEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( edge.getSource(), v2 ) ); new_edge.importUserData( edge ); } Object[] outEdges = v1.getOutEdges().toArray(); for (int x = 0; x < outEdges.length; x++) { DirectedSparseEdge edge = (DirectedSparseEdge)outEdges[ x ]; DirectedSparseEdge new_edge = (DirectedSparseEdge)_graph.addEdge( new DirectedSparseEdge( v2, edge.getDest() ) ); new_edge.importUserData( edge ); } _logger.debug( "Remvoing merged vertex(" + v1.hashCode() + ")" ); } _graph.removeVertex( v1 ); } _logger.debug( "Done merging" ); }
1,125,425
private void executeMethod( boolean optimize ) throws FoundNoEdgeException { DirectedSparseEdge edge = null; Object[] outEdges = null; if ( _nextVertex.containsUserDatumKey( BACK_KEY ) && _history. size() >= 3 ) { Float probability = (Float)_nextVertex.getUserDatum( BACK_KEY ); int index = _radomGenerator.nextInt( 100 ); if ( index < ( probability.floatValue() * 100 ) ) { String str = (String)_history.removeLast(); _logger.debug( "Remove from history: " + str ); String nodeLabel = (String)_history.getLast(); _logger.debug( "Reversing a vertex. From: " + (String)_nextVertex.getUserDatum( LABEL_KEY ) + ", to: " + nodeLabel ); Object[] vertices = _graph.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; if ( nodeLabel == (String)vertex.getUserDatum( LABEL_KEY ) ) { try { _nextVertex = vertex; String label = "PressBackButton"; _logger.debug( "Invoke method for edge: \"" + label + "\"" ); invokeMethod( label ); label = nodeLabel; _logger.debug( "Invoke method for vertex: \"" + label + "\"" ); invokeMethod( label ); } catch( GoBackToPreviousVertexException e ) { throw new RuntimeException( "An GoBackToPreviousVertexException was thrown where it should not be thrown." ); } return; } } throw new RuntimeException( "An attempt was made to reverse to vertex: " + nodeLabel + ", and did not find it." ); } } _logger.debug( "Vertex = " + (String)_nextVertex.getUserDatum( LABEL_KEY ) ); outEdges = _nextVertex.getOutEdges().toArray(); _logger.debug( "Number of outgoing edges = " + outEdges.length ); outEdges = shuffle( outEdges ); if ( _shortestPathToVertex == null && _runUntilAllEdgesVisited == true ) { Vector unvisitedEdges = returnUnvisitedEdge(); if ( unvisitedEdges.size() == 0) { _logger.debug( "All edges has been visited!" ); return; } _logger.info( "Found " + unvisitedEdges.size() + " unvisited edges." ); Object[] shuffledList = shuffle( unvisitedEdges.toArray() ); DirectedSparseEdge e = (DirectedSparseEdge)shuffledList[ 0 ]; if ( e == null ) { throw new RuntimeException( "Found an empty edge!" ); } _logger.info( "Selecting edge: " + getCompleteEdgeName( e ) ); _shortestPathToVertex = new DijkstraShortestPath( _graph ).getPath( _nextVertex, e.getSource() ); _shortestPathToVertex.add( e ); _logger.info( "Intend to take the shortest path between: " + (String)_nextVertex.getUserDatum( LABEL_KEY ) + " and " + (String)e.getDest().getUserDatum( LABEL_KEY ) + " (from: " + (String)e.getSource().getUserDatum( LABEL_KEY ) + "), using " + _shortestPathToVertex.size() + " hops." ); String paths = "The route is: "; for (Iterator iter = _shortestPathToVertex.iterator(); iter.hasNext();) { DirectedSparseEdge item = (DirectedSparseEdge) iter.next(); paths += getCompleteEdgeName( item ) + " ==> "; } paths += " Done!"; _logger.info( paths ); } if ( _shortestPathToVertex != null && _shortestPathToVertex.size() > 0 ) { edge = (DirectedSparseEdge)_shortestPathToVertex.get( 0 ); _shortestPathToVertex.remove( 0 ); _logger.debug( "Removed edge: " + getCompleteEdgeName( edge ) + " from the shortest path list, " + _shortestPathToVertex.size() + " hops remaining." ); if ( _shortestPathToVertex.size() == 0 ) { _shortestPathToVertex = null; } } else if ( optimize ) { // Look for an edge that has not been visited yet. for ( int i = 0; i < outEdges.length; i++ ) { edge = (DirectedSparseEdge)outEdges[ i ]; Integer vistited = (Integer)edge.getUserDatum( VISITED_KEY ); if ( vistited.intValue() == 0 ) { if ( _rejectedEdge == edge ) { // This edge has been rejected, because some condition was not fullfilled. // Try with the next edge in the for-loop. // _rejectedEdge has to be set to null, because it can be valid next time. _rejectedEdge = null; } else { _logger.debug( "Found an edge which has not been visited yet: " + getCompleteEdgeName( edge ) ); break; } } edge = null; } if ( edge == null ) { _logger.debug( "All edges has been visited (" + outEdges.length + ")" ); edge = getWeightedEdge( _nextVertex ); } } else { edge = getWeightedEdge( _nextVertex ); } if ( edge == null ) { throw new RuntimeException( "Did not find any edge." ); } _logger.debug( "Edge = \"" + getCompleteEdgeName( edge ) + "\"" ); _prevVertex = _nextVertex; _nextVertex = (DirectedSparseVertex)edge.getDest(); try { String label = (String)edge.getUserDatum( LABEL_KEY ); _logger.debug( "Invoke method for edge: \"" + label + "\"" ); invokeMethod( label ); Integer vistited = (Integer)edge.getUserDatum( VISITED_KEY ); vistited = new Integer( vistited.intValue() + 1 ); edge.setUserDatum( VISITED_KEY, vistited, UserData.SHARED ); label = (String)edge.getDest().getUserDatum( LABEL_KEY ); _logger.debug( "Invoke method for vertex: \"" + label + "\"" ); invokeMethod( label ); vistited = (Integer)edge.getDest().getUserDatum( VISITED_KEY ); vistited = new Integer( vistited.intValue() + 1 ); edge.getDest().setUserDatum( VISITED_KEY, vistited, UserData.SHARED ); if ( ((String)edge.getDest().getUserDatum( LABEL_KEY )).equals( "Stop" ) ) { _logger.debug( "Clearing the history" ); _history.clear(); } if ( edge.containsUserDatumKey( NO_HISTORY ) == false ) { _logger.debug( "Add to history: " + getCompleteEdgeName( edge ) ); _history.add( (String)edge.getDest().getUserDatum( LABEL_KEY ) ); } } catch( GoBackToPreviousVertexException e ) { _logger.debug( "The edge: " + getCompleteEdgeName( edge ) + " can not be run due to unfullfilled conditions." ); _logger.debug( "Trying from vertex: " + (String)_prevVertex.getUserDatum( LABEL_KEY ) + " again." ); _rejectedEdge = edge; _nextVertex = _prevVertex; } }
private void executeMethod( boolean optimize ) throws FoundNoEdgeException { DirectedSparseEdge edge = null; Object[] outEdges = null; if ( _nextVertex.containsUserDatumKey( BACK_KEY ) && _history. size() >= 3 ) { Float probability = (Float)_nextVertex.getUserDatum( BACK_KEY ); int index = _radomGenerator.nextInt( 100 ); if ( index < ( probability.floatValue() * 100 ) ) { String str = (String)_history.removeLast(); _logger.debug( "Remove from history: " + str ); String nodeLabel = (String)_history.getLast(); _logger.debug( "Reversing a vertex. From: " + (String)_nextVertex.getUserDatum( LABEL_KEY ) + ", to: " + nodeLabel ); Object[] vertices = _graph.getVertices().toArray(); for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; if ( nodeLabel == (String)vertex.getUserDatum( LABEL_KEY ) ) { try { _nextVertex = vertex; String label = "PressBackButton"; _logger.debug( "Invoke method for edge: \"" + label + "\"" ); invokeMethod( label ); label = nodeLabel; _logger.debug( "Invoke method for vertex: \"" + label + "\"" ); invokeMethod( label ); } catch( GoBackToPreviousVertexException e ) { throw new RuntimeException( "An GoBackToPreviousVertexException was thrown where it should not be thrown." ); } return; } } throw new RuntimeException( "An attempt was made to reverse to vertex: " + nodeLabel + ", and did not find it." ); } } _logger.debug( "Vertex = " + (String)_nextVertex.getUserDatum( LABEL_KEY ) ); outEdges = _nextVertex.getOutEdges().toArray(); _logger.debug( "Number of outgoing edges = " + outEdges.length ); outEdges = shuffle( outEdges ); if ( _shortestPathToVertex == null && _runUntilAllEdgesVisited == true ) { Vector unvisitedEdges = returnUnvisitedEdge(); if ( unvisitedEdges.size() == 0) { _logger.debug( "All edges has been visited!" ); return; } _logger.info( "Found " + unvisitedEdges.size() + " unvisited edges." ); Object[] shuffledList = shuffle( unvisitedEdges.toArray() ); DirectedSparseEdge e = (DirectedSparseEdge)shuffledList[ 0 ]; if ( e == null ) { throw new RuntimeException( "Found an empty edge!" ); } _logger.info( "Selecting edge: " + getCompleteEdgeName( e ) ); _shortestPathToVertex = new DijkstraShortestPath( _graph ).getPath( _nextVertex, e.getSource() ); _shortestPathToVertex.add( e ); _logger.info( "Intend to take the shortest path between: " + _nextVertex.getUserDatum( LABEL_KEY ) + " and " + (String)e.getDest().getUserDatum( LABEL_KEY ) + " (from: " + e.getSource().getUserDatum( LABEL_KEY ) + "), using " + _shortestPathToVertex.size() + " hops." ); String paths = "The route is: "; for (Iterator iter = _shortestPathToVertex.iterator(); iter.hasNext();) { DirectedSparseEdge item = (DirectedSparseEdge) iter.next(); paths += getCompleteEdgeName( item ) + " ==> "; } paths += " Done!"; _logger.info( paths ); } if ( _shortestPathToVertex != null && _shortestPathToVertex.size() > 0 ) { edge = (DirectedSparseEdge)_shortestPathToVertex.get( 0 ); _shortestPathToVertex.remove( 0 ); _logger.debug( "Removed edge: " + getCompleteEdgeName( edge ) + " from the shortest path list, " + _shortestPathToVertex.size() + " hops remaining." ); if ( _shortestPathToVertex.size() == 0 ) { _shortestPathToVertex = null; } } else if ( optimize ) { // Look for an edge that has not been visited yet. for ( int i = 0; i < outEdges.length; i++ ) { edge = (DirectedSparseEdge)outEdges[ i ]; Integer vistited = (Integer)edge.getUserDatum( VISITED_KEY ); if ( vistited.intValue() == 0 ) { if ( _rejectedEdge == edge ) { // This edge has been rejected, because some condition was not fullfilled. // Try with the next edge in the for-loop. // _rejectedEdge has to be set to null, because it can be valid next time. _rejectedEdge = null; } else { _logger.debug( "Found an edge which has not been visited yet: " + getCompleteEdgeName( edge ) ); break; } } edge = null; } if ( edge == null ) { _logger.debug( "All edges has been visited (" + outEdges.length + ")" ); edge = getWeightedEdge( _nextVertex ); } } else { edge = getWeightedEdge( _nextVertex ); } if ( edge == null ) { throw new RuntimeException( "Did not find any edge." ); } _logger.debug( "Edge = \"" + getCompleteEdgeName( edge ) + "\"" ); _prevVertex = _nextVertex; _nextVertex = (DirectedSparseVertex)edge.getDest(); try { String label = (String)edge.getUserDatum( LABEL_KEY ); _logger.debug( "Invoke method for edge: \"" + label + "\"" ); invokeMethod( label ); Integer vistited = (Integer)edge.getUserDatum( VISITED_KEY ); vistited = new Integer( vistited.intValue() + 1 ); edge.setUserDatum( VISITED_KEY, vistited, UserData.SHARED ); label = (String)edge.getDest().getUserDatum( LABEL_KEY ); _logger.debug( "Invoke method for vertex: \"" + label + "\"" ); invokeMethod( label ); vistited = (Integer)edge.getDest().getUserDatum( VISITED_KEY ); vistited = new Integer( vistited.intValue() + 1 ); edge.getDest().setUserDatum( VISITED_KEY, vistited, UserData.SHARED ); if ( ((String)edge.getDest().getUserDatum( LABEL_KEY )).equals( "Stop" ) ) { _logger.debug( "Clearing the history" ); _history.clear(); } if ( edge.containsUserDatumKey( NO_HISTORY ) == false ) { _logger.debug( "Add to history: " + getCompleteEdgeName( edge ) ); _history.add( (String)edge.getDest().getUserDatum( LABEL_KEY ) ); } } catch( GoBackToPreviousVertexException e ) { _logger.debug( "The edge: " + getCompleteEdgeName( edge ) + " can not be run due to unfullfilled conditions." ); _logger.debug( "Trying from vertex: " + (String)_prevVertex.getUserDatum( LABEL_KEY ) + " again." ); _rejectedEdge = edge; _nextVertex = _prevVertex; } }
1,125,426
private void invokeMethod( String method ) throws GoBackToPreviousVertexException { Class cls = _object.getClass(); try { if ( method.compareTo( "" ) != 0 ) { Method meth = cls.getMethod( method, null ); meth.invoke( _object, null ); } } catch( NoSuchMethodException e ) { _logger.error( e ); _logger.error( "Try to invoke method: " + method ); throw new RuntimeException( "The methoden is not defined: " + method ); } catch( java.lang.reflect.InvocationTargetException e ) { if ( e.getTargetException().getClass() == GoBackToPreviousVertexException.class ) { throw new GoBackToPreviousVertexException(); } _logger.error( e.getCause().getMessage() ); e.getCause().printStackTrace(); throw new RuntimeException( e.getCause().getMessage() ); } catch( Exception e ) { _logger.error( e ); e.printStackTrace(); throw new RuntimeException( "Abrupt end of execution: " + e.getMessage() ); } }
private void invokeMethod( String method ) throws GoBackToPreviousVertexException { Class cls = _object.getClass(); try { if ( method.compareTo( "" ) != 0 ) { Method meth = cls.getMethod( method, null ); meth.invoke( _object, null ); } } catch( NoSuchMethodException e ) { _logger.error( e ); _logger.error( "Try to invoke method: " + method ); throw new RuntimeException( "The method is not defined: " + method ); } catch( java.lang.reflect.InvocationTargetException e ) { if ( e.getTargetException().getClass() == GoBackToPreviousVertexException.class ) { throw new GoBackToPreviousVertexException(); } _logger.error( e.getCause().getMessage() ); e.getCause().printStackTrace(); throw new RuntimeException( e.getCause().getMessage() ); } catch( Exception e ) { _logger.error( e ); e.printStackTrace(); throw new RuntimeException( "Abrupt end of execution: " + e.getMessage() ); } }
1,125,427
PropertyTabSheet(final Panel panel, final boolean styleProperties) { super(styleProperties ? "Styles" : "Properties"); final GridBox gb = initGridBox(); gb.setPosition(GAP, GAP); final Divider div = new Divider(); div.setX(GAP); div.setHeight(6); final Label lbl = new Label("Edit Property Value:"); lbl.setAlignX(AlignX.RIGHT); lbl.setX(GAP); lbl.setHeight(EDITOR_HEIGHT); editor = defaultEditor = new TextField(); editor.setVisible(false); editor.setHeight(EDITOR_HEIGHT); final Button b = new Button("Apply"); b.setEnabled(false); b.setSize(90, EDITOR_HEIGHT); b.setStandard(true); addPropertyChangeListener(Main.SIZE_ARY, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if (getInnerHeight() > 20 && getInnerWidth() > 20) { gb.setSize(getInnerWidth() - GAP * 2, getInnerHeight() - GAP * 2 - div.getHeight() - editor.getHeight()); div.setY(gb.getY() + gb.getHeight()); div.setWidth(gb.getWidth()); int y = div.getY() + div.getHeight(); lbl.setY(y); int width = (gb.getWidth() - GAP * 4 - b.getWidth()) / 2; lbl.setWidth(width); editor.setPosition(lbl.getX() + lbl.getWidth() + GAP, y); editor.setWidth(width); b.setPosition(editor.getX() + editor.getWidth() + GAP, y); } } }); gb.addPropertyChangeListener(GridBox.Row.PROPERTY_ROW_SELECTED, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { GridBox.Row row = gb.getSelectedRow(); editor.setVisible(false); MaskEditorComponent ed; String value; if (row == null) { ed = defaultEditor; value = ""; b.setEnabled(false); } else { Property prop = (Property)row.get(COL_PROPERTY); ed = propToEditor.get(prop); if (ed == null) propToEditor.put(prop, ed = prop.newEditor()); value = row.get(COL_VALUE).toString(); b.setEnabled(true); } ed.setBounds(editor.getX(), editor.getY(), editor.getWidth(), editor.getHeight()); ed.setText(value); ed.setVisible(true); if (ed.getParent() == null) { int index = getChildren().indexOf(b); getChildren().add(index, ed); } editor = ed; } }); b.addActionListener(Button.ACTION_CLICK, new ActionListener() { public void actionPerformed(ActionEvent ev) { GridBox.Row row = gb.getSelectedRow(); if (row != null) { row.set(COL_VALUE, editor.getText()); Property prop = (Property)row.get(COL_PROPERTY); if (prop != null && panel.getChildren().size() > 0) { for (int i = 0, cnt = panel.getChildren().size(); i < cnt; i++) { Component comp = panel.getChildren().get(i); String name = prop.getName(); if (comp instanceof RadioButton) { String value = editor.getText(); if (i > 0 && name.equals(RadioButton.PROPERTY_CHECKED)) continue; else if (name.equals(TextComponent.PROPERTY_TEXT)) value += (i + 1); else if (name.equals(Component.PROPERTY_X) || name.equals(name.equals(Component.PROPERTY_Y))) { int oldValue = (Integer)prop.getValue(comp); oldValue += Integer.parseInt(value) - oldValue; value = String.valueOf(oldValue); } prop.setValue(comp, value); } else { prop.setValue(comp, editor.getText()); } } } } } }); panel.addItemChangeListener(new ItemChangeListener() { public void itemChange(ItemChangeEvent ev) { if (ev.getType() == ItemChangeEvent.Type.ADD && panel.getChildren().size() == 1) { gb.getRows().clear(); Component comp = panel.getChildren().get(0); for (Property prop : Property.values()) { if (prop.isValidFor(comp) && prop.isStyleProperty() == styleProperties) { GridBox.Row row = new GridBox.Row(); row.add(Main.getSimpleClassName(prop.getType()).replace('$', '.')); row.add(prop.getName()); row.add(prop.getDefaultValue(comp)); row.add(prop == Property.FX_VISIBLE_CHANGE ? FX.Type.NONE : prop.getValue(comp)); row.add(prop); gb.getRows().add(row); } } } } }); getChildren().add(gb); getChildren().add(div); getChildren().add(lbl); getChildren().add(editor); getChildren().add(b); }
PropertyTabSheet(final Panel panel, final boolean styleProperties) { super(styleProperties ? "Styles" : "Properties"); final GridBox gb = initGridBox(); gb.setPosition(GAP, GAP); final Divider div = new Divider(); div.setX(GAP); div.setHeight(6); final Label lbl = new Label("Edit Property Value:"); lbl.setAlignX(AlignX.RIGHT); lbl.setX(GAP); lbl.setHeight(EDITOR_HEIGHT); editor = defaultEditor = new TextField(); editor.setVisible(false); editor.setHeight(EDITOR_HEIGHT); final Button b = new Button("Apply"); b.setEnabled(false); b.setSize(90, EDITOR_HEIGHT); b.setStandard(true); addPropertyChangeListener(Main.SIZE_ARY, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { if (getInnerHeight() > 20 && getInnerWidth() > 20) { gb.setSize(getInnerWidth() - GAP * 2, getInnerHeight() - GAP * 2 - div.getHeight() - editor.getHeight()); div.setY(gb.getY() + gb.getHeight()); div.setWidth(gb.getWidth()); int y = div.getY() + div.getHeight(); lbl.setY(y); int width = (gb.getWidth() - GAP * 4 - b.getWidth()) / 2; lbl.setWidth(width); editor.setPosition(lbl.getX() + lbl.getWidth() + GAP, y); editor.setWidth(width); b.setPosition(editor.getX() + editor.getWidth() + GAP, y); } } }); gb.addPropertyChangeListener(GridBox.Row.PROPERTY_ROW_SELECTED, new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent ev) { GridBox.Row row = gb.getSelectedRow(); editor.setVisible(false); MaskEditorComponent ed; String value; if (row == null) { ed = defaultEditor; value = ""; b.setEnabled(false); } else { Property prop = (Property)row.get(COL_PROPERTY); ed = propToEditor.get(prop); if (ed == null) propToEditor.put(prop, ed = prop.newEditor()); value = row.get(COL_VALUE).toString(); b.setEnabled(true); } ed.setBounds(editor.getX(), editor.getY(), editor.getWidth(), editor.getHeight()); ed.setText(value); ed.setVisible(true); if (ed.getParent() == null) { int index = getChildren().indexOf(b); getChildren().add(index, ed); } editor = ed; } }); b.addActionListener(Button.ACTION_CLICK, new ActionListener() { public void actionPerformed(ActionEvent ev) { GridBox.Row row = gb.getSelectedRow(); if (row != null) { row.set(COL_VALUE, editor.getText()); Property prop = (Property)row.get(COL_PROPERTY); if (prop != null && panel.getChildren().size() > 0) { for (int i = 0, cnt = panel.getChildren().size(); i < cnt; i++) { Component comp = panel.getChildren().get(i); String name = prop.getName(); if (comp instanceof RadioButton) { String value = editor.getText(); if (i > 0 && name.equals(RadioButton.PROPERTY_CHECKED)) continue; else if (name.equals(TextComponent.PROPERTY_TEXT)) value += (i + 1); else if (name.equals(Component.PROPERTY_X) || name.equals(name.equals(Component.PROPERTY_Y))) { int oldValue = (Integer)prop.getValue(comp); oldValue += Integer.parseInt(value) - oldValue; value = String.valueOf(oldValue); } prop.setValue(comp, value); } else { prop.setValue(comp, editor.getText()); } } } } } }); panel.addItemChangeListener(new ItemChangeListener() { public void itemChange(ItemChangeEvent ev) { if (ev.getType() == ItemChangeEvent.Type.ADD && panel.getChildren().size() == 1) { gb.getRows().clear(); Component comp = panel.getChildren().get(0); for (Property prop : Property.values()) { if (prop.isValidFor(comp) && prop.isStyleProperty() == styleProperties) { GridBox.Row row = new GridBox.Row(); row.add(Main.getSimpleClassName(prop.getType()).replace('$', '.')); row.add(prop.getName()); row.add(prop.getDefaultValue(comp)); row.add(prop == Property.FX_VISIBLE_CHANGE ? FX.Type.NONE : prop.getValue(comp)); row.add(prop); gb.getRows().add(row); } } } } }); getChildren().add(gb); getChildren().add(div); getChildren().add(lbl); getChildren().add(editor); getChildren().add(b); }
1,125,428
public void itemChange(ItemChangeEvent ev) { if (ev.getType() == ItemChangeEvent.Type.ADD && panel.getChildren().size() == 1) { gb.getRows().clear(); Component comp = panel.getChildren().get(0); for (Property prop : Property.values()) { if (prop.isValidFor(comp) && prop.isStyleProperty() == styleProperties) { GridBox.Row row = new GridBox.Row(); row.add(Main.getSimpleClassName(prop.getType()).replace('$', '.')); row.add(prop.getName()); row.add(prop.getDefaultValue(comp)); row.add(prop == Property.FX_VISIBLE_CHANGE ? FX.Type.NONE : prop.getValue(comp)); row.add(prop); gb.getRows().add(row); } } } }
public void itemChange(ItemChangeEvent ev) { if (ev.getType() == ItemChangeEvent.Type.ADD && panel.getChildren().size() == 1) { gb.getRows().clear(); Component comp = panel.getChildren().get(0); for (Property prop : Property.values()) { if (prop.isValidFor(comp) && prop.isStyleProperty() == styleProperties) { GridBox.Row row = new GridBox.Row(); row.add(Main.getSimpleClassName(prop.getType()).replace('$', '.')); row.add(prop.getName()); row.add(prop.getDefaultValue(comp)); row.add(prop == Property.FX_VISIBLE_CHANGE ? FX.Type.NONE : prop.getValue(comp)); row.add(prop); gb.getRows().add(row); } } } }
1,125,430
public synchronized void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; _numActive--; if(success) { _pool.add(new SoftReference(obj)); } notifyAll(); // _numActive has changed if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public synchronized void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; _numActive--; if(success) { _pool.add(new SoftReference(obj, refQueue)); } notifyAll(); // _numActive has changed if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
1,125,434
public void run() { CursorableLinkedList.Cursor objcursor = null; CursorableLinkedList.Cursor keycursor = null; Object key = null; while(!_cancelled) { long sleeptime = 0L; synchronized(GenericKeyedObjectPool.this) { sleeptime = _timeBetweenEvictionRunsMillis; } try { Thread.currentThread().sleep(sleeptime); } catch(Exception e) { ; // ignored } try { synchronized(GenericKeyedObjectPool.this) { for(int i=0,m=getNumTests();i<m;i++) { if(_poolMap.size() > 0) { // if we don't have a key cursor, then create one, and close any object cursor if(null == keycursor) { keycursor = _poolList.cursor(); key = null; if(null != objcursor) { objcursor.close(); objcursor = null; } } // if we don't have an object cursor if(null == objcursor) { // if the keycursor has a next value, then use it if(keycursor.hasNext()) { key = keycursor.next(); CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); objcursor = pool.cursor(pool.size()); } else { // else close the key cursor and loop back around if(null != keycursor) { keycursor.close(); keycursor = _poolList.cursor(); if(null != objcursor) { objcursor.close(); objcursor = null; } } continue; } } // if the objcursor has a previous object, then test it if(objcursor.hasPrevious()) { ObjectTimestampPair pair = (ObjectTimestampPair)(objcursor.previous()); if(System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { try { objcursor.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); // if that was the last object for that key, drop that pool if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; // ignored } } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(key,pair.value); active = true; } catch(Exception e) { objcursor.remove(); try { _factory.passivateObject(key,pair.value); } catch(Exception ex) { ; // ignored } _factory.destroyObject(key,pair.value); } if(active) { if(!_factory.validateObject(key,pair.value)) { try { objcursor.remove(); _totalIdle--; try { _factory.passivateObject(key,pair.value); } catch(Exception e) { ; // ignored } _factory.destroyObject(key,pair.value); if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; // ignored } } else { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { objcursor.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } } } } } else { // else the objcursor is done, so close it and loop around if(objcursor != null) { objcursor.close(); objcursor = null; } } } } } } catch(Exception e) { ; // ignored } } if(null != keycursor) { keycursor.close(); } if(null != objcursor) { objcursor.close(); } }
public void run() { CursorableLinkedList.Cursor objcursor = null; CursorableLinkedList.Cursor keycursor = null; Object key = null; while(!_cancelled) { long sleeptime = 0L; synchronized(GenericKeyedObjectPool.this) { sleeptime = _timeBetweenEvictionRunsMillis; } try { Thread.currentThread().sleep(sleeptime); } catch(Exception e) { ; // ignored } try { synchronized(GenericKeyedObjectPool.this) { for(int i=0,m=getNumTests();i<m;i++) { if(_poolMap.size() > 0) { // if we don't have a key cursor, then create one, and close any object cursor if(null == keycursor) { keycursor = _poolList.cursor(); key = null; if(null != objcursor) { objcursor.close(); objcursor = null; } } // if we don't have an object cursor if(null == objcursor) { // if the keycursor has a next value, then use it if(keycursor.hasNext()) { key = keycursor.next(); CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); objcursor = pool.cursor(pool.size()); } else { // else close the key cursor and loop back around if(null != keycursor) { keycursor.close(); keycursor = _poolList.cursor(); if(null != objcursor) { objcursor.close(); objcursor = null; } } continue; } } // if the objcursor has a previous object, then test it if(objcursor.hasPrevious()) { ObjectTimestampPair pair = (ObjectTimestampPair)(objcursor.previous()); if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { try { objcursor.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); // if that was the last object for that key, drop that pool if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; // ignored } } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(key,pair.value); active = true; } catch(Exception e) { objcursor.remove(); try { _factory.passivateObject(key,pair.value); } catch(Exception ex) { ; // ignored } _factory.destroyObject(key,pair.value); } if(active) { if(!_factory.validateObject(key,pair.value)) { try { objcursor.remove(); _totalIdle--; try { _factory.passivateObject(key,pair.value); } catch(Exception e) { ; // ignored } _factory.destroyObject(key,pair.value); if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; // ignored } } else { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { objcursor.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } } } } } else { // else the objcursor is done, so close it and loop around if(objcursor != null) { objcursor.close(); objcursor = null; } } } } } } catch(Exception e) { ; // ignored } } if(null != keycursor) { keycursor.close(); } if(null != objcursor) { objcursor.close(); } }
1,125,435
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } } _pool.add(new SoftReference(obj)); }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } } _pool.add(new SoftReference(obj)); }
1,125,436
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } } _pool.add(new SoftReference(obj)); }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(success) { _pool.add(new SoftReference(obj)); } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { } } }
1,125,437
public abstract Object makeObject(Object key);
public abstract Object makeObject(Object key) throws Exception;
1,125,438
public void returnObject(Object key, Object obj) throws Exception { // grab the pool (list) of objects associated with the given key CursorableLinkedList pool = null; synchronized(this) { pool = (CursorableLinkedList)(_poolMap.get(key)); // if it doesn't exist, create it if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key, pool); _poolList.add(key); } } // if we need to validate this object, do so boolean success = true; // whether or not this object passed validation if((_testOnReturn && !_factory.validateObject(key, obj))) { success = false; try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored } } else { try { _factory.passivateObject(key, obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = false; synchronized(this) { // subtract one from the total and keyed active counts _totalActive--; Integer active = (Integer)(_activeMap.get(key)); if(null == active) { // do nothing, either null or zero is OK } else if(active.intValue() <= 1) { _activeMap.remove(key); } else { _activeMap.put(key, new Integer(active.intValue() - 1)); } // if there's no space in the pool, flag the object // for destruction // else if we passivated succesfully, return it to the pool if(_maxIdle > 0 && (pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { pool.addFirst(new ObjectTimestampPair(obj)); _totalIdle++; } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored? } } }
public void returnObject(Object key, Object obj) throws Exception { // grab the pool (list) of objects associated with the given key CursorableLinkedList pool = null; synchronized(this) { pool = (CursorableLinkedList)(_poolMap.get(key)); // if it doesn't exist, create it if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key, pool); _poolList.add(key); } } // if we need to validate this object, do so boolean success = true; // whether or not this object passed validation if((_testOnReturn && !_factory.validateObject(key, obj))) { success = false; try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored } } else { try { _factory.passivateObject(key, obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = false; synchronized(this) { // subtract one from the total and keyed active counts _totalActive--; Integer active = (Integer)(_activeMap.get(key)); if(null == active) { // do nothing, either null or zero is OK } else if(active.intValue() <= 1) { _activeMap.remove(key); } else { _activeMap.put(key, new Integer(active.intValue() - 1)); } // if there's no space in the pool, flag the object // for destruction // else if we passivated succesfully, return it to the pool if(_maxIdle >= 0 && (pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { pool.addFirst(new ObjectTimestampPair(obj)); _totalIdle++; } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(key, obj); } catch(Exception e) { // ignored? } } }
1,125,439
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(null != _factory) { if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(_pool.size() >= _maxSleeping) { shouldDestroy = true; } else if(success) { _pool.push(obj); } notifyAll(); // _numActive has changed } if(shouldDestroy) { // by constructor, shouldDestroy is false when _factory is null try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(null != _factory) { if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(_pool.size() >= _maxSleeping) { shouldDestroy = true; } else if(success) { _pool.push(obj); } notifyAll(); // _numActive has changed } if(shouldDestroy) { // by constructor, shouldDestroy is false when _factory is null try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
1,125,440
public static void main(String[] args) { if ( args.length < 2 ) { System.out.println( "Too few arguments" ); displayHelpMessage(); return; } try { _mtb = new ModelBasedTesting( args[ 0 ] ); _mtb.generateJavaCode_XDE( args[ 1 ] ); } catch ( RuntimeException e ) { System.out.println( e.getMessage() ); } }
public static void main(String[] args) { if ( args.length < 2 ) { System.out.println( "Too few arguments" ); displayHelpMessage(); return; } try { _mtb = new ModelBasedTesting( args[ 0 ] ); _mtb.generateJavaCode_XDE( args[ 1 ] ); } catch ( RuntimeException e ) { e.printStackTrace(); } }
1,125,442
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
public ModelBasedTesting( String graphmlFileName_, Object object_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
1,125,443
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = object_; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
1,125,444
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); readFiles(); }
1,125,445
public void activateObject(Object key, Object obj) { }
public void activateObject(Object key, Object obj) throws Exception { }
1,125,446
public void destroyObject(Object key, Object obj) { }
public void destroyObject(Object key, Object obj) throws Exception { }
1,125,447
public void passivateObject(Object key, Object obj) { }
public void passivateObject(Object key, Object obj) throws Exception { }
1,125,448
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
1,125,449
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(_pool.size() >= _maxSleeping) { shouldDestroy = true; } else if(success) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
1,125,450
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
1,125,451
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(null == _factory || _factory.validateObject(obj)) { if(null != _factory) { try { _factory.passivateObject(obj); } catch(Exception e) { _factory.destroyObject(obj); return; } } if(_pool.size() < _maxSleeping) { _pool.push(obj); } else { if(null != _factory) { _factory.destroyObject(obj); } } } else { if(null != _factory) { _factory.destroyObject(obj); } } }
1,125,452
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive < 0 || _numActive < _maxActive) { // allow new object to be created } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: // allow new object to be created break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException("Pool exhausted"); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("WhenExhaustedAction property " + _whenExhaustedAction + " not recognized."); } } } _numActive++; // create new object when needed if(null == pair) { try { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } catch (Throwable e) { // object cannot be created _numActive--; notifyAll(); if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new Exception(e); } } } // activate & validate the object try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("ValidateObject failed"); } return pair.value; } catch (Throwable e) { // object cannot be activated or is invalid _numActive--; notifyAll(); try { _factory.destroyObject(pair.value); } catch (Throwable e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage()); } else { continue; // keep looping } } } }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(_pool.removeFirst()); } catch(NoSuchElementException e) { ; /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) if(_maxActive < 0 || _numActive < _maxActive) { // allow new object to be created } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: // allow new object to be created break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException("Pool exhausted"); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { final long elapsed = (System.currentTimeMillis() - starttime); final long waitTime = _maxWait - elapsed; if (waitTime > 0) { wait(waitTime); } } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("WhenExhaustedAction property " + _whenExhaustedAction + " not recognized."); } } } _numActive++; // create new object when needed if(null == pair) { try { Object obj = _factory.makeObject(); pair = new ObjectTimestampPair(obj); newlyCreated = true; } catch (Throwable e) { // object cannot be created _numActive--; notifyAll(); if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new Exception(e); } } } // activate & validate the object try { _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { throw new Exception("ValidateObject failed"); } return pair.value; } catch (Throwable e) { // object cannot be activated or is invalid _numActive--; notifyAll(); try { _factory.destroyObject(pair.value); } catch (Throwable e2) { // cannot destroy broken object } if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object, cause: " + e.getMessage()); } else { continue; // keep looping } } } }
1,125,454
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { if(null == _evictionCursor) { _evictionCursor = (_pool.cursor(_pool.size())); } else if(!_evictionCursor.hasPrevious()) { _evictionCursor.close(); _evictionCursor = (_pool.cursor(_pool.size())); } for(int i=0,m=getNumTests();i<m;i++) { if(!_evictionCursor.hasPrevious()) { _evictionCursor.close(); _evictionCursor = (_pool.cursor(_pool.size())); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(_evictionCursor.previous()); if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { removeObject = true; } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(pair.value); active = true; } catch(Exception e) { removeObject=true; } if(active) { if(!_factory.validateObject(pair.value)) { removeObject=true; } else { try { _factory.passivateObject(pair.value); } catch(Exception e) { removeObject=true; } } } } if(removeObject) { try { _evictionCursor.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } } // if !empty }
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { if(null == _evictionCursor) { _evictionCursor = (_pool.cursor(_pool.size())); } else if(!_evictionCursor.hasPrevious()) { _evictionCursor.close(); _evictionCursor = (_pool.cursor(_pool.size())); } for(int i=0,m=getNumTests();i<m;i++) { if(!_evictionCursor.hasPrevious()) { _evictionCursor.close(); _evictionCursor = (_pool.cursor(_pool.size())); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(_evictionCursor.previous()); if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { removeObject = true; } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(pair.value); active = true; } catch(Exception e) { removeObject=true; } if(active) { if(!_factory.validateObject(pair.value)) { removeObject=true; } else { try { _factory.passivateObject(pair.value); } catch(Exception e) { removeObject=true; } } } } if(removeObject) { try { _evictionCursor.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } } // if !empty }
1,125,455
public TestKeyedObjectPoolFactory(final String name) { super(name); }
protected TestKeyedObjectPoolFactory(final String name) { super(name); }
1,125,456
protected KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException{ throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
protected KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException{ throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
1,125,457
public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); }
public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); }
1,125,458
public GenericObjectPool() { this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
public GenericObjectPool() { this(null,DEFAULT_MAX_ACTIVE,DEFAULT_WHEN_EXHAUSTED_ACTION,DEFAULT_MAX_WAIT,DEFAULT_MAX_IDLE,DEFAULT_MIN_IDLE,DEFAULT_TEST_ON_BORROW,DEFAULT_TEST_ON_RETURN,DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS,DEFAULT_NUM_TESTS_PER_EVICTION_RUN,DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS,DEFAULT_TEST_WHILE_IDLE); }
1,125,459
public synchronized void evict() throws Exception { Object key = null; if (_recentlyEvictedKeys == null) { _recentlyEvictedKeys = new HashSet(_poolMap.size()); } Set remainingKeys = new HashSet(_poolMap.keySet()); remainingKeys.removeAll(_recentlyEvictedKeys); Iterator keyIter = remainingKeys.iterator(); ListIterator objIter = null; for(int i=0,m=getNumTests();i<m;i++) { if(_poolMap.size() > 0) { // Find next idle object pool key to work on if (key == null) { if (!keyIter.hasNext()) { _recentlyEvictedKeys.clear(); remainingKeys = new HashSet(_poolMap.keySet()); keyIter = remainingKeys.iterator(); } if (!keyIter.hasNext()) { // done, there are no keyed pools return; } key = keyIter.next(); } // if we don't have a keyed object pool iterator if (objIter == null) { final LinkedList list = (LinkedList)_poolMap.get(key); if (_evictLastIndex < 0 || _evictLastIndex > list.size()) { _evictLastIndex = list.size(); } objIter = list.listIterator(_evictLastIndex); } // if the _evictionCursor has a previous object, then test it if(objIter.hasPrevious()) { ObjectTimestampPair pair = (ObjectTimestampPair)(objIter.previous()); boolean removeObject=false; if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { removeObject=true; } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(key,pair.value); active = true; } catch(Exception e) { removeObject=true; } if(active) { if(!_factory.validateObject(key,pair.value)) { removeObject=true; } else { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { removeObject=true; } } } } if(removeObject) { try { objIter.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); // Do not remove the key from the _poolList or _poolmap, even if the list // stored in the _poolMap for this key is empty when the // {@link #getMinIdle <i>minIdle</i>} is > 0. // // Otherwise if it was the last object for that key, drop that pool if ((_minIdle == 0) && (((LinkedList)(_poolMap.get(key))).isEmpty())) { _poolMap.remove(key); } } catch(Exception e) { ; // ignored } } } else { // else done evicting keyed pool _recentlyEvictedKeys.add(key); _evictLastIndex = -1; objIter = null; } } } }
public synchronized void evict() throws Exception { Object key = null; if (_recentlyEvictedKeys == null) { _recentlyEvictedKeys = new HashSet(_poolMap.size()); } Set remainingKeys = new HashSet(_poolMap.keySet()); remainingKeys.removeAll(_recentlyEvictedKeys); Iterator keyIter = remainingKeys.iterator(); ListIterator objIter = null; for(int i=0,m=getNumTests();i<m;i++) { if(_poolMap.size() > 0) { // Find next idle object pool key to work on if (key == null) { if (!keyIter.hasNext()) { _recentlyEvictedKeys.clear(); remainingKeys = new HashSet(_poolMap.keySet()); keyIter = remainingKeys.iterator(); } if (!keyIter.hasNext()) { // done, there are no keyed pools return; } key = keyIter.next(); } // if we don't have a keyed object pool iterator if (objIter == null) { final LinkedList list = (LinkedList)_poolMap.get(key); if (_evictLastIndex < 0 || _evictLastIndex > list.size()) { _evictLastIndex = list.size(); } objIter = list.listIterator(_evictLastIndex); } // if the _evictionCursor has a previous object, then test it if(objIter.hasPrevious()) { ObjectTimestampPair pair = (ObjectTimestampPair)(objIter.previous()); boolean removeObject=false; if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { removeObject=true; } if(_testWhileIdle && removeObject == false) { boolean active = false; try { _factory.activateObject(key,pair.value); active = true; } catch(Exception e) { removeObject=true; } if(active) { if(!_factory.validateObject(key,pair.value)) { removeObject=true; } else { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { removeObject=true; } } } } if(removeObject) { try { objIter.remove(); _totalIdle--; _factory.destroyObject(key,pair.value); // Do not remove the key from the _poolList or _poolmap, even if the list // stored in the _poolMap for this key is empty when the // {@link #getMinIdle <i>minIdle</i>} is > 0. // // Otherwise if it was the last object for that key, drop that pool if ((_minIdle == 0) && (((LinkedList)(_poolMap.get(key))).isEmpty())) { _poolMap.remove(key); } } catch(Exception e) { ; // ignored } } } else { // else done evicting keyed pool _recentlyEvictedKeys.add(key); _evictLastIndex = -1; objIter = null; } } } }
1,125,462
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clearOldest(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive < 0 || active < _maxActive) && (_maxTotal < 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } }
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); boolean newlyCreated = false; for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // if there is a totalMaxActive and we are at the limit then // we have to make room if ((_maxTotal > 0) && (_totalActive + _totalIdle >= _maxTotal)) { clearOldest(); } // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = getActiveCount(key); if ((_maxActive < 0 || active < _maxActive) && (_maxTotal < 0 || _totalActive + _totalIdle < _maxTotal)) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); newlyCreated = true; } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { final long elapsed = (System.currentTimeMillis() - starttime); final long waitTime = _maxWait - elapsed; if (waitTime > 0) { wait(waitTime); } } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { _factory.destroyObject(key,pair.value); if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); } // else keep looping } else { incrementActiveCount(key); return pair.value; } } }
1,125,463
protected synchronized void startEvictor(long delay) { if(null != _evictor) { _evictor.cancel(); _evictor = null; } if(delay > 0) { _evictor = new Evictor(delay); Thread t = new Thread(_evictor); t.setDaemon(true); t.start(); } }
protected synchronized void startEvictor(long delay) { if(null != _evictor) { _evictor.cancel(); _evictor = null; } if(delay > 0) { _evictor = new Evictor(delay); Thread t = new Thread(_evictor); t.setDaemon(true); t.start(); } }
1,125,465
public void addObject() throws Exception { Object obj = _factory.makeObject(); synchronized(this) { _numActive++; // A little slimy - must do this because returnObject decrements it. this.returnObject(obj); } }
public void addObject() throws Exception { Object obj = _factory.makeObject(); synchronized(this) { _numActive++; // A little slimy - must do this because returnObject decrements it. this.returnObject(obj); } }
1,125,466
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(_testOnReturn && !(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { _pool.addFirst(new ObjectTimestampPair(obj)); } notifyAll(); // _numActive has changed } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
public void returnObject(Object obj) throws Exception { assertOpen(); boolean success = true; if(_testOnReturn && !(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false; } } boolean shouldDestroy = !success; synchronized(this) { _numActive--; if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) { shouldDestroy = true; } else if(success) { _pool.addFirst(new ObjectTimestampPair(obj)); } notifyAll(); // _numActive has changed } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { // ignored } } }
1,125,467
public int size() { if (prune) { synchronized (getObjectPool().getPool()) { final Iterator iter = super.listIterator(); while (iter.hasNext()) { final EvictorReference ref = (EvictorReference)iter.next(); if (ref != null && ref.get() == null) { iter.remove(); } } } } return super.size(); }
public int size() { if (prune) { synchronized (getObjectPool().getPool()) { final Iterator iter = super.listIterator(); while (iter.hasNext()) { final EvictorReference ref = (EvictorReference)iter.next(); if (ref != null && ref.get() == null) { iter.remove(); } } } } return super.size(); }
1,125,468
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); Document doc = parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
1,125,470
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
1,125,471
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
1,125,472
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( org.jdom.JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
private SparseGraph parseFile( String fileName ) { SparseGraph graph = new SparseGraph(); graph.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); try { _logger.info( "Parsing file: " + fileName ); _doc = _parser.build( fileName ); // Parse all vertices (nodes) Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; if ( element.getAttributeValue( "yfiles.foldertype" ) != null ) { _logger.debug( "Excluded node: " + element.getAttributeValue( "yfiles.foldertype" ) ); continue; } _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "NodeLabel" ) ); while ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { org.jdom.Element nodeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + nodeLabel.getQualifiedName() ); _logger.debug( "Name: " + nodeLabel.getTextTrim() ); DirectedSparseVertex v = (DirectedSparseVertex) graph.addVertex( new DirectedSparseVertex() ); v.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); v.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); v.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); String str = nodeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label; if ( m.find( )) { label = m.group( 1 ); v.addUserDatum( LABEL_KEY, label, UserData.SHARED ); } else { throw new RuntimeException( "Label must be defined." ); } _logger.debug( "Added vertex: " + v.getUserDatum( LABEL_KEY ) ); // If merge is defined, find it... // If defined, it means that the node will be merged with all other nodes wit the same name, // but not replaced by any subgraphs p = Pattern.compile( "\\n(MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found MERGE for vertex: " + label ); } // If no merge is defined, find it... // If defined, it means that when merging graphs, this specific vertex will not be merged // or replaced by any subgraphs p = Pattern.compile( "\\n(NO_MERGE)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { v.addUserDatum( NO_MERGE, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found NO_MERGE for vertex: " + label ); } // If BLOCKED is defined, find it... // If defined, it means that this vertex will not be added to the graph // Sometimes it can be useful during testing to mark vertcies as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This vetex will be removed from the graph: " + label ); v.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // NOTE: Only for html applications // In browsers, the usage of the 'Back'-button can be used. // If defined, with a value value, which depicts the probability for the edge // to be executed, tha back-button will be pressed in the browser. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(back=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find( ) ) { Float probability; String value = m.group( 2 ); try { probability = Float.valueOf( value.trim() ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", back is not a correct float value: " + error.toString() ); } _logger.debug( "Found FLOAT value: " + probability + ", for vertex: " + label ); v.addUserDatum( BACK_KEY, probability, UserData.SHARED ); } } } } } Object[] vertices = graph.getVertices().toArray(); // Parse all edges (arrows or transtitions) iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) ); while ( iter.hasNext() ) { Object o = iter.next(); if ( o instanceof org.jdom.Element ) { org.jdom.Element element = (org.jdom.Element)o; _logger.debug( "id: " + element.getAttributeValue( "id" ) ); Iterator iter2 = element.getDescendants( new org.jdom.filter.ElementFilter( "EdgeLabel" ) ); org.jdom.Element edgeLabel = null; if ( iter2.hasNext() ) { Object o2 = iter2.next(); if ( o2 instanceof org.jdom.Element ) { edgeLabel = (org.jdom.Element)o2; _logger.debug( "Full name: " + edgeLabel.getQualifiedName() ); _logger.debug( "Name: " + edgeLabel.getTextTrim() ); } } _logger.debug( "source: " + element.getAttributeValue( "source" ) ); _logger.debug( "target: " + element.getAttributeValue( "target" ) ); DirectedSparseVertex source = null; DirectedSparseVertex dest = null; for ( int i = 0; i < vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)vertices[ i ]; // Find source vertex if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "source" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { source = vertex; } if ( vertex.getUserDatum( ID_KEY ).equals( element.getAttributeValue( "target" ) ) && vertex.getUserDatum( FILE_KEY ).equals( fileName ) ) { dest = vertex; } } if ( source == null ) { String msg = "Could not find starting node for edge. Name: " + element.getAttributeValue( "source" ); _logger.error( msg ); throw new RuntimeException( msg ); } if ( dest == null ) { String msg = "Could not find end node for edge. Name: " + element.getAttributeValue( "target" ); _logger.error( msg ); throw new RuntimeException( msg ); } DirectedSparseEdge e = new DirectedSparseEdge( source, dest ); graph.addEdge( e ); e.addUserDatum( ID_KEY, element.getAttributeValue( "id" ), UserData.SHARED ); e.addUserDatum( FILE_KEY, fileName, UserData.SHARED ); if ( edgeLabel != null ) { String str = edgeLabel.getTextTrim(); Pattern p = Pattern.compile( "(.*)", Pattern.MULTILINE ); Matcher m = p.matcher( str ); String label = null; if ( m.find() ) { label = m.group( 1 ); if ( !label.equalsIgnoreCase("") ) { e.addUserDatum( LABEL_KEY, label, UserData.SHARED ); _logger.debug( "Found label= " + label + " for edge id: " + edgeLabel.getQualifiedName() ); } } else { throw new RuntimeException( "Label for edge must be defined." ); } if ( label == null || label.equalsIgnoreCase("") ) { DirectedSparseVertex srcV = (DirectedSparseVertex)e.getSource(); String s = (String)srcV.getUserDatum( LABEL_KEY ); if ( s.compareTo( START_NODE ) != 0 ) { throw new RuntimeException( "Label for a edge comming from a non-Start vertex, must be defined." ); } } // If weight is defined, find it... // weight must be associated with a value, which depicts the probability for the edge // to be executed. // A value of 0.05 is the same as 5% chance of going down this road. p = Pattern.compile( "\\n(weight=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { Float weight; String value = m.group( 2 ); try { weight = Float.valueOf( value.trim() ); _logger.debug( "Found weight= " + weight + " for edge: " + label ); } catch ( NumberFormatException error ) { throw new RuntimeException( "For label: " + label + ", weight is not a correct float value: " + error.toString() ); } e.addUserDatum( WEIGHT_KEY, weight, UserData.SHARED ); } // If BLOCKED is defined, find it... // If defined, it means that this edge will not be added to the graph // Sometimes it can be useful during testing to mark edges as BLOCKED // due to bugs in the system you test. When the bug is removed, the BLOCKED // tag can be removed. p = Pattern.compile( "\\n(BLOCKED)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { _logger.debug( "Found BLOCKED. This edge will be removed from the graph: " + label ); e.addUserDatum( BLOCKED, BLOCKED, UserData.SHARED ); } // If No_history is defined, find it... // If defined, it means that when executing this edge, it shall not // be added to the history list of passed edgses. p = Pattern.compile( "\\n(No_history)", Pattern.MULTILINE ); m = p.matcher( str ); if ( m.find() ) { e.addUserDatum( NO_HISTORY, m.group( 1 ), UserData.SHARED ); _logger.debug( "Found No_history for edge: " + label ); } // If condition used defined, find it... p = Pattern.compile( "\\n(if: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); HashMap conditions = null; while ( m.find( ) ) { if ( conditions == null ) { conditions = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); conditions.put( variable, state ); _logger.debug( "Condition: " + variable + " = " + state ); } if ( conditions != null ) { e.addUserDatum( CONDITION_KEY, conditions, UserData.SHARED ); } // If state are defined, find them... HashMap states = null; p = Pattern.compile( "\\n(state: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( states == null ) { states = new HashMap(); } String variable = m.group( 2 ); Boolean state = Boolean.valueOf( m.group( 3 ) ); states.put( variable, state ); _logger.debug( "State: " + variable + " = " + state ); } if ( states != null ) { e.addUserDatum( STATE_KEY, states, UserData.SHARED ); } // If string variables are defined, find them... HashMap variables = null; p = Pattern.compile( "\\n(string: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); String variable = m.group( 3 ); variables.put( variableLabel, variable ); _logger.debug( "String variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(integer: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Integer variable = Integer.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Integer variable: " + variableLabel + " = " + variable ); } // If integer variables are defined, find them... p = Pattern.compile( "\\n(float: (.*)=(.*))", Pattern.MULTILINE ); m = p.matcher( str ); while ( m.find( ) ) { if ( variables == null ) { variables = new HashMap(); } String variableLabel = m.group( 2 ); Float variable = Float.valueOf( m.group( 3 ) ); variables.put( variableLabel, variable ); _logger.debug( "Float variable: " + variableLabel + " = " + variable ); } if ( variables != null ) { e.addUserDatum( VARIABLE_KEY, variables, UserData.SHARED ); } } String str = (String)e.getUserDatum( LABEL_KEY ); if ( str == null || str.equals( "" ) ) { DirectedSparseVertex v = (DirectedSparseVertex)e.getSource(); str = (String)v.getUserDatum( LABEL_KEY ); if ( str.equals( "Start" ) == false ) { throw new RuntimeException( "Found an edge with no (or empty) label. This is only allowed when the source vertex is a Start vertex." ); } } e.addUserDatum( VISITED_KEY, new Integer( 0 ), UserData.SHARED ); _logger.debug( "Adderade edge: \"" + e.getUserDatum( LABEL_KEY ) + "\"" ); } } } catch ( JDOMException e ) { _logger.error( e ); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } catch ( IOException e ) { e.printStackTrace(); throw new RuntimeException( "Kunde inte skanna filen: " + fileName ); } removeBlockedEntities( graph ); return graph; }
1,125,473
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = 0; Integer act = (Integer)(_activeMap.get(key)); if(null != act) { active = act.intValue(); } if(_maxActive > 0 && active < _maxActive) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { ; // ignored, we're throwing it out anyway } _factory.destroyObject(key,pair.value); } else { Integer active = (Integer)(_activeMap.get(key)); if(null == active) { _activeMap.put(key,new Integer(1)); } else { _activeMap.put(key,new Integer(active.intValue() + 1)); } _totalActive++; return pair.value; } } }
public synchronized Object borrowObject(Object key) throws Exception { long starttime = System.currentTimeMillis(); for(;;) { CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); if(null == pool) { pool = new CursorableLinkedList(); _poolMap.put(key,pool); _poolList.add(key); } ObjectTimestampPair pair = null; // if there are any sleeping, just grab one of those try { pair = (ObjectTimestampPair)(pool.removeFirst()); if(null != pair) { _totalIdle--; } } catch(NoSuchElementException e) { /* ignored */ } // otherwise if(null == pair) { // check if we can create one // (note we know that the num sleeping is 0, else we wouldn't be here) int active = 0; Integer act = (Integer)(_activeMap.get(key)); if(null != act) { active = act.intValue(); } if(_maxActive <= 0 || active < _maxActive) { Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); } else { // the pool is exhausted switch(_whenExhaustedAction) { case WHEN_EXHAUSTED_GROW: Object obj = _factory.makeObject(key); pair = new ObjectTimestampPair(obj); break; case WHEN_EXHAUSTED_FAIL: throw new NoSuchElementException(); case WHEN_EXHAUSTED_BLOCK: try { if(_maxWait <= 0) { wait(); } else { wait(_maxWait); } } catch(InterruptedException e) { // ignored } if(_maxWait > 0 && ((System.currentTimeMillis() - starttime) >= _maxWait)) { throw new NoSuchElementException("Timeout waiting for idle object"); } else { continue; // keep looping } default: throw new IllegalArgumentException("whenExhaustedAction " + _whenExhaustedAction + " not recognized."); } } } _factory.activateObject(key,pair.value); if(_testOnBorrow && !_factory.validateObject(key,pair.value)) { try { _factory.passivateObject(key,pair.value); } catch(Exception e) { ; // ignored, we're throwing it out anyway } _factory.destroyObject(key,pair.value); } else { Integer active = (Integer)(_activeMap.get(key)); if(null == active) { _activeMap.put(key,new Integer(1)); } else { _activeMap.put(key,new Integer(active.intValue() + 1)); } _totalActive++; return pair.value; } } }
1,125,474
public Object makeObject() { counter++; return String.valueOf(counter); }
public Object makeObject() { counter++; return new String(String.valueOf(counter)); }
1,125,475
public void testOutOfMemory() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); Object obj = pool.borrowObject(); assertEquals("1", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("2", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
public void testOutOfMemory() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); Object obj = pool.borrowObject(); assertEquals("1", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("2", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
1,125,476
public void testOutOfMemory() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); Object obj = pool.borrowObject(); assertEquals("1", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("2", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
public void testOutOfMemory() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); Object obj = pool.borrowObject(); assertEquals("1", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("2", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
1,125,477
public void testOutOfMemory1000() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); for (int i = 0 ; i < 1000 ; i++) { pool.addObject(); } Object obj = pool.borrowObject(); assertEquals("1000", obj); pool.returnObject(obj); obj = null; assertEquals(1000, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("1001", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
public void testOutOfMemory1000() throws Exception { pool = new SoftReferenceObjectPool(new SmallPoolableObjectFactory()); for (int i = 0 ; i < 1000 ; i++) { pool.addObject(); } Object obj = pool.borrowObject(); assertEquals("1000", obj); pool.returnObject(obj); obj = null; assertEquals(1000, pool.getNumIdle()); try { HashMap map = new HashMap(); for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } obj = pool.borrowObject(); assertEquals("1001", obj); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
1,125,478