rem
stringlengths
0
477k
add
stringlengths
0
313k
context
stringlengths
6
599k
protected ObjectPoolFactory makeFactory(PoolableObjectFactory objectFactory) throws UnsupportedOperationException { throw new UnsupportedOperationException("Subclass needs to override makeFactory method.");
protected ObjectPoolFactory makeFactory() throws UnsupportedOperationException { return makeFactory(new MethodCallPoolableObjectFactory());
protected ObjectPoolFactory makeFactory(PoolableObjectFactory objectFactory) throws UnsupportedOperationException { throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
public synchronized void returnObject(Object obj) throws Exception { _numActive--; if(_maxIdle > 0 && (_pool.size() >= _maxIdle || (_testOnReturn && !_factory.validateObject(obj)))) {
public void returnObject(Object obj) throws Exception { boolean success = true; if(_testOnReturn && !(_factory.validateObject(obj))) { success = false; } else {
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 }
; } _factory.destroyObject(obj); } else { try { _factory.passivateObject(obj); _pool.addFirst(new ObjectTimestampPair(obj)); } catch(Exception e) { _factory.destroyObject(obj);
success = false;
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 }
notifyAll();
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) { } }
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 int getNumIdle(Object key) { try { return((LinkedList)(_poolMap.get(key))).size(); } catch(Exception e) { return 0; }
public synchronized int getNumIdle() { return _totalIdle;
public synchronized int getNumIdle(Object key) { try { return((LinkedList)(_poolMap.get(key))).size(); } catch(Exception e) { return 0; } }
public synchronized int getNumActive(Object key) { return getActiveCount(key);
public synchronized int getNumActive() { return _totalActive;
public synchronized int getNumActive(Object key) { return getActiveCount(key); }
if(newlyCreated) { throw new NoSuchElementException("Could not create a validated object"); }
public synchronized Object borrowObject() throws Exception { assertOpen(); long starttime = System.currentTimeMillis(); 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); } 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."); } } } _factory.activateObject(pair.value); if(_testOnBorrow && !_factory.validateObject(pair.value)) { _factory.destroyObject(pair.value); } else { _numActive++; return pair.value; } } }
if ((_maxActive <= 0 || active < _maxActive) && (_maxTotal <= 0 || _totalActive + _totalIdle < _maxTotal)) {
if ((_maxActive < 0 || active < _maxActive) && (_maxTotal < 0 || _totalActive + _totalIdle < _maxTotal)) {
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 int getNumActive() throws UnsupportedOperationException {
public int getNumActive(Object key) throws UnsupportedOperationException {
public int getNumActive() throws UnsupportedOperationException { return -1; }
public int getNumIdle() throws UnsupportedOperationException {
public int getNumIdle(Object key) throws UnsupportedOperationException {
public int getNumIdle() throws UnsupportedOperationException { return -1; }
public void activateObject(Object obj) {
public void activateObject(Object obj) throws Exception {
public void activateObject(Object obj) { }
public void destroyObject(Object obj) {
public void destroyObject(Object obj) throws Exception {
public void destroyObject(Object obj) { }
public void passivateObject(Object obj) {
public void passivateObject(Object obj) throws Exception {
public void passivateObject(Object obj) { }
protected TestObjectPoolFactory(final String name) {
public TestObjectPoolFactory(final String name) {
protected TestObjectPoolFactory(final String name) { super(name); }
if((_maxIdle > 0) && (_pool.size() >= _maxIdle)) {
if((_maxIdle >= 0) && (_pool.size() >= _maxIdle)) {
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 boolean validateObject(Object key, Object obj) { return true; }
public boolean validateObject(Object key, Object obj) { return valid; }
public boolean validateObject(Object key, Object obj) { return true; }
IdentityKey(final int ident) { this.ident = ident;
IdentityKey(final Object obj) { this(System.identityHashCode(obj));
IdentityKey(final int ident) { this.ident = ident; }
return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle);
return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle,_softMinEvictableIdleTimeMillis);
public ObjectPool createPool() { return new GenericObjectPool(_factory,_maxActive,_whenExhaustedAction,_maxWait,_maxIdle,_minIdle,_testOnBorrow,_testOnReturn,_timeBetweenEvictionRunsMillis,_numTestsPerEvictionRun,_minEvictableIdleTimeMillis,_testWhileIdle); }
protected TestKeyedObjectPoolFactory(final String name) {
public TestKeyedObjectPoolFactory(final String name) {
protected TestKeyedObjectPoolFactory(final String name) { super(name); }
g.addUserDatum( LABEL_KEY, edge.getDest().getUserDatum(LABEL_KEY), UserData.SHARED );
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" ); }
_logger.debug( "Investigating graph: " + _graph.getUserDatum( LABEL_KEY ) );
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" ); }
_logger.debug( "With graph: " + g.getUserDatum( LABEL_KEY ) + " in file: " + g.getUserDatum( FILE_KEY ) ); if ( _graph.getUserDatum( LABEL_KEY ).equals( g.getUserDatum( LABEL_KEY ) ) )
if ( _graph.hashCode() == g.hashCode() )
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" ); }
_logger.debug( " Graphs are the same, next..." );
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" ); }
_logger.debug( "Analysing graph in file: " + g.getUserDatum( FILE_KEY ) );
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" ); }
boolean v1IsMerged = false;
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" ); }
} _graph.removeVertex( v1 ); }
_graph.removeVertex( v1 ); } }
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" ); }
_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." );
_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." );
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; } }
throw new RuntimeException( "The methoden is not defined: " + method );
throw new RuntimeException( "The method is not defined: " + method );
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() ); } }
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);
if (comp.getUserObject() instanceof Widget) { Class<? extends Component> type = ((Widget)comp.getUserObject()).getType(); if (type == TabSheet.class) comp = ((TabFolder)comp).getChildren().get(((TabFolder)comp).getCurrentIndex()); for (Property prop : Property.values()) { if (prop.isValidFor(type) && 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.getValue(comp)); row.add(prop); gb.getRows().add(row); }
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); }
Class<? extends Component> type = ((Widget)comp.getUserObject()).getType(); if (type == TabSheet.class) comp = ((TabFolder)comp).getChildren().get(((TabFolder)comp).getCurrentIndex());
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()); } } } } }
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);
if (comp.getUserObject() instanceof Widget) { Class<? extends Component> type = ((Widget)comp.getUserObject()).getType(); if (type == TabSheet.class) comp = ((TabFolder)comp).getChildren().get(((TabFolder)comp).getCurrentIndex()); for (Property prop : Property.values()) { if (prop.isValidFor(type) && 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.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); } } } }
ref.clear();
public synchronized Object borrowObject() throws Exception { assertOpen(); Object obj = null; while(null == obj) { if(_pool.isEmpty()) { if(null == _factory) { throw new NoSuchElementException(); } else { obj = _factory.makeObject(); } } else { SoftReference ref = (SoftReference)(_pool.remove(_pool.size() - 1)); obj = ref.get(); } if(null != _factory && null != obj) { _factory.activateObject(obj); } if (null != _factory && null != obj && !_factory.validateObject(obj)) { _factory.destroyObject(obj); obj = null; } } _numActive++; return obj; }
pruneClearedReferences();
public synchronized void clear() { assertOpen(); if(null != _factory) { Iterator iter = _pool.iterator(); while(iter.hasNext()) { try { Object obj = ((SoftReference)iter.next()).get(); if(null != obj) { _factory.destroyObject(obj); } } catch(Exception e) { // ignore error, keep destroying the rest } } } _pool.clear(); }
pruneClearedReferences();
public synchronized int getNumIdle() { assertOpen(); return _pool.size(); }
_pool.add(new SoftReference(obj));
_pool.add(new SoftReference(obj, refQueue));
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 } } }
if(System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) {
if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) {
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 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; }
public void returnObject(Object obj) throws Exception { boolean success = true; if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false;
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)); }
_pool.add(new SoftReference(obj));
boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(success) { _pool.add(new SoftReference(obj)); } notifyAll(); } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { } }
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 abstract Object makeObject(Object key);
public abstract Object makeObject(Object key) throws Exception;
public abstract Object makeObject(Object key);
if(_maxIdle > 0 && (pool.size() >= _maxIdle)) {
if(_maxIdle >= 0 && (pool.size() >= _maxIdle)) {
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? } } }
if(_pool.size() >= _maxSleeping) { shouldDestroy = true; } else if(success) {
if (success) { Object toBeDestroyed = null; if(_pool.size() >= _maxSleeping) { shouldDestroy = true; toBeDestroyed = _pool.remove(0); }
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 } } }
obj = toBeDestroyed;
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 } } }
System.out.println( e.getMessage() );
e.printStackTrace();
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 ModelBasedTesting( String graphmlFileName_ )
public ModelBasedTesting( String graphmlFileName_, Object object_ )
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
_object = null;
_object = object_;
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
PropertyConfigurator.configure("log4j.properties");
public ModelBasedTesting( String graphmlFileName_ ) { _graphmlFileName = graphmlFileName_; _object = null; _logger = org.apache.log4j.Logger.getLogger( ModelBasedTesting.class ); PropertyConfigurator.configure("log4j.properties"); readFiles(); }
public void activateObject(Object key, Object obj) {
public void activateObject(Object key, Object obj) throws Exception {
public void activateObject(Object key, Object obj) { }
public void destroyObject(Object key, Object obj) {
public void destroyObject(Object key, Object obj) throws Exception {
public void destroyObject(Object key, Object obj) { }
public void passivateObject(Object key, Object obj) {
public void passivateObject(Object key, Object obj) throws Exception {
public void passivateObject(Object key, Object 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; }
public void returnObject(Object obj) throws Exception { boolean success = true; if(!(_factory.validateObject(obj))) { success = false; } else { try { _factory.passivateObject(obj); } catch(Exception e) { success = false;
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); } } }
if(_pool.size() < _maxSleeping) {
} boolean shouldDestroy = !success; synchronized(this) { _numActive--; if(_pool.size() >= _maxSleeping) { shouldDestroy = true; } else if(success) {
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); } } }
} 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); } } }
} else { if(null != _factory) {
notifyAll(); } if(shouldDestroy) { try {
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); } } }
} catch(Exception e) {
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); } } }
wait(_maxWait);
final long elapsed = (System.currentTimeMillis() - starttime); final long waitTime = _maxWait - elapsed; if (waitTime > 0) { wait(waitTime); }
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 } } } }
if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { removeObject = true;
long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { removeObject = true; } else if ((_softMinEvictableIdleTimeMillis > 0) && (idleTimeMilis > _softMinEvictableIdleTimeMillis) && (getNumIdle() > getMinIdle())) { removeObject = true;
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 TestKeyedObjectPoolFactory(final String name) {
protected TestKeyedObjectPoolFactory(final String name) {
public TestKeyedObjectPoolFactory(final String name) { super(name); }
protected KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException{ throw new UnsupportedOperationException("Subclass needs to override makeFactory method.");
protected KeyedObjectPoolFactory makeFactory() throws UnsupportedOperationException { return makeFactory(createObjectFactory());
protected KeyedObjectPoolFactory makeFactory(KeyedPoolableObjectFactory objectFactory) throws UnsupportedOperationException{ throw new UnsupportedOperationException("Subclass needs to override makeFactory method."); }
public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
public StackKeyedObjectPoolFactory() { this((KeyedPoolableObjectFactory)null,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY);
public StackKeyedObjectPoolFactory(KeyedPoolableObjectFactory factory) { this(factory,StackKeyedObjectPool.DEFAULT_MAX_SLEEPING,StackKeyedObjectPool.DEFAULT_INIT_SLEEPING_CAPACITY); }
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);
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);
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); }
} int objectDeficit = getMinIdle() - getNumIdle(); if (_maxActive > 0) { int growLimit = Math.max(0, getMaxActive() - getNumActive() - getNumIdle()); objectDeficit = Math.min(objectDeficit, growLimit); } for ( int j = 0; j < objectDeficit; j++ ) { addObject();
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 } } } } } }
setMinIdle(conf.minIdle);
public synchronized void setConfig(GenericObjectPool.Config conf) { setMaxIdle(conf.maxIdle); setMaxActive(conf.maxActive); setMaxWait(conf.maxWait); setWhenExhaustedAction(conf.whenExhaustedAction); setTestOnBorrow(conf.testOnBorrow); setTestOnReturn(conf.testOnReturn); setTestWhileIdle(conf.testWhileIdle); setNumTestsPerEvictionRun(conf.numTestsPerEvictionRun); setMinEvictableIdleTimeMillis(conf.minEvictableIdleTimeMillis); setTimeBetweenEvictionRunsMillis(conf.timeBetweenEvictionRunsMillis); notifyAll(); }
} else if(_testWhileIdle) {
} if(_testWhileIdle && removeObject == false) {
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; } } } }
wait(_maxWait);
final long elapsed = (System.currentTimeMillis() - starttime); final long waitTime = _maxWait - elapsed; if (waitTime > 0) { wait(waitTime); }
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; } } }
assertNotNull(pool);
public void testInvalidWhenExhaustedAction() throws Exception { try { pool.setWhenExhaustedAction(Byte.MAX_VALUE); fail("Expected IllegalArgumentException"); } catch(IllegalArgumentException e) { // expected } try { ObjectPool pool = new GenericObjectPool( new SimpleFactory(), GenericObjectPool.DEFAULT_MAX_ACTIVE, Byte.MAX_VALUE, GenericObjectPool.DEFAULT_MAX_WAIT, GenericObjectPool.DEFAULT_MAX_IDLE, false, false, GenericObjectPool.DEFAULT_TIME_BETWEEN_EVICTION_RUNS_MILLIS, GenericObjectPool.DEFAULT_NUM_TESTS_PER_EVICTION_RUN, GenericObjectPool.DEFAULT_MIN_EVICTABLE_IDLE_TIME_MILLIS, false ); fail("Expected IllegalArgumentException"); } catch(IllegalArgumentException e) { // expected } }
_evictor = new Evictor(delay); Thread t = new Thread(_evictor); t.setDaemon(true); t.start();
_evictor = new Evictor(); EVICTION_TIMER.schedule(_evictor, delay, delay);
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(); } }
synchronized(this) { _numActive++; this.returnObject(obj); }
addObjectToPool(obj, false);
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); } }
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(); } if(shouldDestroy) { try { _factory.destroyObject(obj); } catch(Exception e) { } }
addObjectToPool(obj, true);
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 } } }
final EvictorReference ref = (EvictorReference)iter.next(); if (ref != null && ref.get() == null) {
Object o = iter.next(); while (o instanceof LenderReference) { o = ((LenderReference)o).get(); } if (o == null) {
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(); }
SAXBuilder parser = new SAXBuilder( "org.apache.crimson.parser.XMLReaderImpl", false );
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; }
_doc = _parser.build( fileName );
Document doc = parser.build( fileName );
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; }
Iterator iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) );
Iterator iter = doc.getDescendants( new org.jdom.filter.ElementFilter( "node" ) );
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; }
iter = _doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) );
iter = doc.getDescendants( new org.jdom.filter.ElementFilter( "edge" ) );
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; }
catch ( org.jdom.JDOMException e )
catch ( JDOMException e )
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; }
if(_maxActive > 0 && active < _maxActive) {
if(_maxActive <= 0 || active < _maxActive) {
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; } } }
return String.valueOf(counter);
return new String(String.valueOf(counter));
public Object makeObject() { counter++; return String.valueOf(counter); }
try { HashMap map = new HashMap();
final List garbage = new LinkedList(); final Runtime runtime = Runtime.getRuntime(); while (pool.getNumIdle() > 0) { garbage.add(new byte[Math.min(1024 * 1024, (int)runtime.freeMemory())]); System.gc(); } garbage.clear(); System.gc();
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()); }
for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { }
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()); }
try { HashMap map = new HashMap();
final List garbage = new LinkedList(); final Runtime runtime = Runtime.getRuntime(); while (pool.getNumIdle() > 0) { garbage.add(new byte[Math.min(1024 * 1024, (int)runtime.freeMemory())]); System.gc(); } garbage.clear(); System.gc();
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()); }
for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { }
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()); }
HashMap map = new HashMap();
final Map map = new HashMap();
public void testOutOfMemoryKeepMap() throws Exception { pool = new SoftReferenceObjectPool(new LargePoolableObjectFactory(1000000)); Object obj = pool.borrowObject(); assertTrue(((String)obj).startsWith("1.")); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); // allocate map outside try/catch block HashMap map = new HashMap(); try { for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } try { obj = pool.borrowObject(); fail("Expected out of memory"); } catch (OutOfMemoryError ex) { } }
for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i));
final Runtime runtime = Runtime.getRuntime(); int i = 0; while (true) { final int size = Math.max(1, Math.min(1048576, (int)runtime.freeMemory() / 2)); final byte[] data = new byte[size]; map.put(new Integer(i++), data);
public void testOutOfMemoryKeepMap() throws Exception { pool = new SoftReferenceObjectPool(new LargePoolableObjectFactory(1000000)); Object obj = pool.borrowObject(); assertTrue(((String)obj).startsWith("1.")); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); // allocate map outside try/catch block HashMap map = new HashMap(); try { for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { } try { obj = pool.borrowObject(); fail("Expected out of memory"); } catch (OutOfMemoryError ex) { } }
try { HashMap map = new HashMap();
final List garbage = new LinkedList(); final Runtime runtime = Runtime.getRuntime(); while (pool.getNumIdle() > 0) { garbage.add(new byte[Math.min(1024 * 1024, (int)runtime.freeMemory())]); System.gc(); } garbage.clear(); System.gc();
public void testOutOfMemoryLarge() throws Exception { pool = new SoftReferenceObjectPool(new LargePoolableObjectFactory(1000000)); Object obj = pool.borrowObject(); assertTrue(((String)obj).startsWith("1.")); 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(); assertTrue(((String)obj).startsWith("2.")); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
for (int i = 0; i < 1000000; i++) { map.put(new Integer(i), new String("Fred Flintstone" + i)); } } catch (OutOfMemoryError ex) { }
public void testOutOfMemoryLarge() throws Exception { pool = new SoftReferenceObjectPool(new LargePoolableObjectFactory(1000000)); Object obj = pool.borrowObject(); assertTrue(((String)obj).startsWith("1.")); 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(); assertTrue(((String)obj).startsWith("2.")); pool.returnObject(obj); obj = null; assertEquals(1, pool.getNumIdle()); }
Thread.currentThread().sleep(_timeBetweenEvictionRunsMillis);
Thread.currentThread().sleep(sleeptime);
public void run() { CursorableLinkedList.Cursor cursor = null; while(!_cancelled) { long sleeptime = 0L; synchronized(GenericObjectPool.this) { sleeptime = _timeBetweenEvictionRunsMillis; } try { Thread.currentThread().sleep(_timeBetweenEvictionRunsMillis); } catch(Exception e) { ; // ignored } try { synchronized(GenericObjectPool.this) { if(!_pool.isEmpty()) { if(null == cursor) { cursor = (CursorableLinkedList.Cursor)(_pool.cursor(_pool.size())); } else if(!cursor.hasPrevious()) { cursor.close(); cursor = (CursorableLinkedList.Cursor)(_pool.cursor(_pool.size())); } for(int i=0,m=getNumTests();i<m;i++) { if(!cursor.hasPrevious()) { cursor.close(); cursor = (CursorableLinkedList.Cursor)(_pool.cursor(_pool.size())); } else { ObjectTimestampPair pair = (ObjectTimestampPair)(cursor.previous()); if(_minEvictableIdleTimeMillis > 0 && System.currentTimeMillis() - pair.tstamp > _minEvictableIdleTimeMillis) { try { cursor.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } else if(_testWhileIdle) { boolean active = false; try { _factory.activateObject(pair.value); active = true; } catch(Exception e) { cursor.remove(); try { _factory.passivateObject(pair.value); } catch(Exception ex) { ; // ignored } _factory.destroyObject(pair.value); } if(active) { if(!_factory.validateObject(pair.value)) { cursor.remove(); try { _factory.passivateObject(pair.value); } catch(Exception ex) { ; // ignored } _factory.destroyObject(pair.value); } else { try { _factory.passivateObject(pair.value); } catch(Exception e) { cursor.remove(); _factory.destroyObject(pair.value); } } } } } } } } } catch(Exception e) { // ignored } } if(null != cursor) { cursor.close(); } }
value = val; tstamp = System.currentTimeMillis();
this(val, System.currentTimeMillis());
ObjectTimestampPair(Object val) { value = val; tstamp = System.currentTimeMillis(); }
sourceFile.append( " print \"Edge: PressBackButton\n\";" );
sourceFile.append( " print \"Edge: PressBackButton\";\n" );
public void generatePerlCode( String fileName ) { boolean _existBack = false; _vertices = _graph.getVertices().toArray(); _edges = _graph.getEdges().toArray(); ArrayList writtenVertices = new ArrayList(); ArrayList writtenEdges = new ArrayList(); StringBuffer sourceFile = new StringBuffer(); /** * Read the original file first. If the methods already are defined in the file, * leave those methods alone. */ BufferedReader input = null; try { _logger.debug( "Try to open file: " + fileName ); input = new BufferedReader( new FileReader( fileName ) ); String line = null; while ( ( line = input.readLine() ) != null ) { sourceFile.append( line ); sourceFile.append( System.getProperty( "line.separator" ) ); } } catch ( FileNotFoundException e ) { _logger.error( "File not found exception: " + e.getMessage() ); } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } finally { try { if ( input != null ) { input.close(); } } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } } _logger.debug( sourceFile.toString() ); for ( int i = 0; i < _vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)_vertices[ i ]; boolean duplicated = false; for ( Iterator iter = writtenVertices.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)vertex.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( _existBack == false ) { _existBack = true; Pattern p = Pattern.compile( "sub PressBackButton\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the edge: PressBackButton\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub PressBackButton()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: PressBackButton\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the verification of the vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenVertices.add( (String)vertex.getUserDatum( LABEL_KEY ) ); } for ( int i = 0; i < _edges.length; i++ ) { DirectedSparseEdge edge = (DirectedSparseEdge)_edges[ i ]; boolean duplicated = false; for ( Iterator iter = writtenEdges.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)edge.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implemets the edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenEdges.add( (String)edge.getUserDatum( LABEL_KEY ) ); } try { FileWriter file = new FileWriter( fileName ); file.write( sourceFile.toString() ); file.flush(); } catch ( IOException e ) { _logger.error( e.getMessage() ); } }
sourceFile.append( " print \"Vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n\";" );
sourceFile.append( " print \"Vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\";\n" );
public void generatePerlCode( String fileName ) { boolean _existBack = false; _vertices = _graph.getVertices().toArray(); _edges = _graph.getEdges().toArray(); ArrayList writtenVertices = new ArrayList(); ArrayList writtenEdges = new ArrayList(); StringBuffer sourceFile = new StringBuffer(); /** * Read the original file first. If the methods already are defined in the file, * leave those methods alone. */ BufferedReader input = null; try { _logger.debug( "Try to open file: " + fileName ); input = new BufferedReader( new FileReader( fileName ) ); String line = null; while ( ( line = input.readLine() ) != null ) { sourceFile.append( line ); sourceFile.append( System.getProperty( "line.separator" ) ); } } catch ( FileNotFoundException e ) { _logger.error( "File not found exception: " + e.getMessage() ); } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } finally { try { if ( input != null ) { input.close(); } } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } } _logger.debug( sourceFile.toString() ); for ( int i = 0; i < _vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)_vertices[ i ]; boolean duplicated = false; for ( Iterator iter = writtenVertices.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)vertex.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( _existBack == false ) { _existBack = true; Pattern p = Pattern.compile( "sub PressBackButton\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the edge: PressBackButton\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub PressBackButton()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: PressBackButton\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the verification of the vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenVertices.add( (String)vertex.getUserDatum( LABEL_KEY ) ); } for ( int i = 0; i < _edges.length; i++ ) { DirectedSparseEdge edge = (DirectedSparseEdge)_edges[ i ]; boolean duplicated = false; for ( Iterator iter = writtenEdges.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)edge.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implemets the edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenEdges.add( (String)edge.getUserDatum( LABEL_KEY ) ); } try { FileWriter file = new FileWriter( fileName ); file.write( sourceFile.toString() ); file.flush(); } catch ( IOException e ) { _logger.error( e.getMessage() ); } }
sourceFile.append( " print \"Edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n\";" );
sourceFile.append( " print \"Edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\";\n" );
public void generatePerlCode( String fileName ) { boolean _existBack = false; _vertices = _graph.getVertices().toArray(); _edges = _graph.getEdges().toArray(); ArrayList writtenVertices = new ArrayList(); ArrayList writtenEdges = new ArrayList(); StringBuffer sourceFile = new StringBuffer(); /** * Read the original file first. If the methods already are defined in the file, * leave those methods alone. */ BufferedReader input = null; try { _logger.debug( "Try to open file: " + fileName ); input = new BufferedReader( new FileReader( fileName ) ); String line = null; while ( ( line = input.readLine() ) != null ) { sourceFile.append( line ); sourceFile.append( System.getProperty( "line.separator" ) ); } } catch ( FileNotFoundException e ) { _logger.error( "File not found exception: " + e.getMessage() ); } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } finally { try { if ( input != null ) { input.close(); } } catch ( IOException e ) { _logger.error( "IO exception: " + e.getMessage() ); } } _logger.debug( sourceFile.toString() ); for ( int i = 0; i < _vertices.length; i++ ) { DirectedSparseVertex vertex = (DirectedSparseVertex)_vertices[ i ]; boolean duplicated = false; for ( Iterator iter = writtenVertices.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)vertex.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( _existBack == false ) { _existBack = true; Pattern p = Pattern.compile( "sub PressBackButton\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the edge: PressBackButton\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub PressBackButton()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: PressBackButton\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implements the verification of the vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)vertex.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Vertex: " + (String)vertex.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenVertices.add( (String)vertex.getUserDatum( LABEL_KEY ) ); } for ( int i = 0; i < _edges.length; i++ ) { DirectedSparseEdge edge = (DirectedSparseEdge)_edges[ i ]; boolean duplicated = false; for ( Iterator iter = writtenEdges.iterator(); iter.hasNext(); ) { String str = (String) iter.next(); if ( str.equals( (String)edge.getUserDatum( LABEL_KEY ) ) == true ) { duplicated = true; break; } } if ( duplicated == false ) { Pattern p = Pattern.compile( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "\\(\\)(.|[\\n\\r])*?\\{(.|[\\n\\r])*?\\}", Pattern.MULTILINE ); Matcher m = p.matcher( sourceFile ); if ( m.find() == false ) { sourceFile.append( "#\n" ); sourceFile.append( "# This method implemets the edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n" ); sourceFile.append( "#\n" ); sourceFile.append( "sub " + (String)edge.getUserDatum( LABEL_KEY ) + "()\n" ); sourceFile.append( "{\n" ); sourceFile.append( " print \"Edge: " + (String)edge.getUserDatum( LABEL_KEY ) + "\n\";" ); sourceFile.append( " die \"Not implemented.\";\n" ); sourceFile.append( "}\n\n" ); } } writtenEdges.add( (String)edge.getUserDatum( LABEL_KEY ) ); } try { FileWriter file = new FileWriter( fileName ); file.write( sourceFile.toString() ); file.flush(); } catch ( IOException e ) { _logger.error( e.getMessage() ); } }
CursorableLinkedList.Cursor objcursor = null; CursorableLinkedList.Cursor keycursor = null; Object key = null;
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(); } }
synchronized(GenericKeyedObjectPool.this) { for(int i=0,m=getNumTests();i<m;i++) { if(_poolMap.size() > 0) { if(null == keycursor) { keycursor = _poolList.cursor(); key = null; if(null != objcursor) { objcursor.close(); objcursor = null; } } if(null == objcursor) { if(keycursor.hasNext()) { key = keycursor.next(); CursorableLinkedList pool = (CursorableLinkedList)(_poolMap.get(key)); objcursor = pool.cursor(pool.size()); } else { if(null != keycursor) { keycursor.close(); keycursor = _poolList.cursor(); if(null != objcursor) { objcursor.close(); objcursor = null; } } continue; } } 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( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; } } 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) { ; } _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) { ; } _factory.destroyObject(key,pair.value); if( ((CursorableLinkedList)(_poolMap.get(key))).isEmpty() ) { _poolMap.remove(key); _poolList.remove(key); } } catch(Exception e) { ; } } 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 { if(objcursor != null) { objcursor.close(); objcursor = null; } } } } }
evict();
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(); } }
if(null != keycursor) { keycursor.close(); } if(null != objcursor) { objcursor.close();
synchronized(GenericKeyedObjectPool.this) { if(null != _evictionCursor) { _evictionCursor.close(); _evictionCursor = null; } if(null != _evictionKeyCursor) { _evictionKeyCursor.close(); _evictionKeyCursor = null; }
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(); } }
if(null != _evictionCursor) { _evictionCursor.close(); _evictionCursor = null; } if(null != _evictionKeyCursor) { _evictionKeyCursor.close(); _evictionKeyCursor = null; }
synchronized public void close() throws Exception { clear(); _poolList = null; _poolMap = null; _activeMap = null; if(null != _evictor) { _evictor.cancel(); _evictor = null; } }
if (referant == null) {
Object r = referant; while (r instanceof LenderReference) { r = ((LenderReference)r).get(); } if (r == null) {
public void run() { // Skip some synchronization if we can if (referant == null) { cancel(); return; } final PoolableObjectFactory factory = getObjectPool().getFactory(); synchronized(getObjectPool().getPool()) { if (referant == null) { cancel(); return; } try { factory.activateObject(referant); if (factory.validateObject(referant)) { factory.passivateObject(referant); } else { factory.destroyObject(referant); clear(); } } catch (Exception e) { clear(); } } }
factory.activateObject(referant); if (factory.validateObject(referant)) { factory.passivateObject(referant);
factory.activateObject(r); if (factory.validateObject(r)) { factory.passivateObject(r);
public void run() { // Skip some synchronization if we can if (referant == null) { cancel(); return; } final PoolableObjectFactory factory = getObjectPool().getFactory(); synchronized(getObjectPool().getPool()) { if (referant == null) { cancel(); return; } try { factory.activateObject(referant); if (factory.validateObject(referant)) { factory.passivateObject(referant); } else { factory.destroyObject(referant); clear(); } } catch (Exception e) { clear(); } } }
factory.destroyObject(referant);
factory.destroyObject(r);
public void run() { // Skip some synchronization if we can if (referant == null) { cancel(); return; } final PoolableObjectFactory factory = getObjectPool().getFactory(); synchronized(getObjectPool().getPool()) { if (referant == null) { cancel(); return; } try { factory.activateObject(referant); if (factory.validateObject(referant)) { factory.passivateObject(referant); } else { factory.destroyObject(referant); clear(); } } catch (Exception e) { clear(); } } }
} else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0)
} boolean removeObject = false; final ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); final long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0)
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { ListIterator iter; if (evictLastIndex < 0) { iter = _pool.listIterator(_pool.size()); } else { iter = _pool.listIterator(evictLastIndex); } for(int i=0,m=getNumTests();i<m;i++) { if(!iter.hasPrevious()) { iter = _pool.listIterator(_pool.size()); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { removeObject = true; } else if ((_softMinEvictableIdleTimeMillis > 0) && (idleTimeMilis > _softMinEvictableIdleTimeMillis) && (getNumIdle() > getMinIdle())) { removeObject = true; } if(_testWhileIdle && removeObject == false) { 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 { iter.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } evictLastIndex = iter.previousIndex(); // resume from here } // if !empty }
removeObject = true;
removeObject = true; } if(_testWhileIdle && !removeObject) { boolean active = false; try { _factory.activateObject(pair.value); active = true; } catch(Exception e) { removeObject=true;
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { ListIterator iter; if (evictLastIndex < 0) { iter = _pool.listIterator(_pool.size()); } else { iter = _pool.listIterator(evictLastIndex); } for(int i=0,m=getNumTests();i<m;i++) { if(!iter.hasPrevious()) { iter = _pool.listIterator(_pool.size()); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { removeObject = true; } else if ((_softMinEvictableIdleTimeMillis > 0) && (idleTimeMilis > _softMinEvictableIdleTimeMillis) && (getNumIdle() > getMinIdle())) { removeObject = true; } if(_testWhileIdle && removeObject == false) { 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 { iter.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } evictLastIndex = iter.previousIndex(); // resume from here } // if !empty }
if(_testWhileIdle && removeObject == false) { boolean active = false; try { _factory.activateObject(pair.value); active = true; } catch(Exception e) {
if(active) { if(!_factory.validateObject(pair.value)) {
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { ListIterator iter; if (evictLastIndex < 0) { iter = _pool.listIterator(_pool.size()); } else { iter = _pool.listIterator(evictLastIndex); } for(int i=0,m=getNumTests();i<m;i++) { if(!iter.hasPrevious()) { iter = _pool.listIterator(_pool.size()); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { removeObject = true; } else if ((_softMinEvictableIdleTimeMillis > 0) && (idleTimeMilis > _softMinEvictableIdleTimeMillis) && (getNumIdle() > getMinIdle())) { removeObject = true; } if(_testWhileIdle && removeObject == false) { 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 { iter.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } evictLastIndex = iter.previousIndex(); // resume from here } // if !empty }
} if(active) { if(!_factory.validateObject(pair.value)) {
} else { try { _factory.passivateObject(pair.value); } catch(Exception e) {
public synchronized void evict() throws Exception { assertOpen(); if(!_pool.isEmpty()) { ListIterator iter; if (evictLastIndex < 0) { iter = _pool.listIterator(_pool.size()); } else { iter = _pool.listIterator(evictLastIndex); } for(int i=0,m=getNumTests();i<m;i++) { if(!iter.hasPrevious()) { iter = _pool.listIterator(_pool.size()); } else { boolean removeObject = false; ObjectTimestampPair pair = (ObjectTimestampPair)(iter.previous()); long idleTimeMilis = System.currentTimeMillis() - pair.tstamp; if ((_minEvictableIdleTimeMillis > 0) && (idleTimeMilis > _minEvictableIdleTimeMillis)) { removeObject = true; } else if ((_softMinEvictableIdleTimeMillis > 0) && (idleTimeMilis > _softMinEvictableIdleTimeMillis) && (getNumIdle() > getMinIdle())) { removeObject = true; } if(_testWhileIdle && removeObject == false) { 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 { iter.remove(); _factory.destroyObject(pair.value); } catch(Exception e) { ; // ignored } } } } evictLastIndex = iter.previousIndex(); // resume from here } // if !empty }