1 19 20 21 package com.hp.hpl.jena.reasoner.dig; 24 25 26 27 import java.util.*; 30 31 32 33 42 public class DIGConnectionPool { 43 46 49 50 private static DIGConnectionPool s_instance = new DIGConnectionPool(); 51 52 53 56 57 private List m_pool = new ArrayList(); 58 59 60 private List m_allocated = new ArrayList(); 61 62 63 66 67 private DIGConnectionPool() {} 68 69 70 73 76 public static DIGConnectionPool getInstance() { 77 return s_instance; 78 } 79 80 81 public DIGConnection allocate() { 82 DIGConnection dc = m_pool.isEmpty() ? new DIGConnection() : (DIGConnection) m_pool.remove( 0 ); 83 m_allocated.add( dc ); 84 85 return dc; 86 } 87 88 89 public DIGConnection allocate( String connectionURL ) { 90 for (int i = 0; i < m_pool.size(); i++) { 92 DIGConnection c = (DIGConnection) m_pool.get( i ); 93 94 if (connectionURL.equals( c.getReasonerURL() )) { 95 m_pool.remove( i ); 96 m_allocated.add( c ); 97 return c; 98 } 99 } 100 101 DIGConnection dc = m_pool.isEmpty() ? new DIGConnection() : (DIGConnection) m_pool.remove( 0 ); 103 m_allocated.add( dc ); 104 dc.setReasonerURL( connectionURL ); 105 106 return dc; 107 } 108 109 110 public void release( DIGConnection dc ) { 111 m_allocated.remove( dc ); 112 m_pool.add( dc ); 113 } 114 115 116 119 123 } 124 125 126 152 | Popular Tags |