|
1 | 1 | /* |
2 | 2 | * The baseCode project |
3 | | - * |
| 3 | + * |
4 | 4 | * Copyright (c) 2013 University of British Columbia |
5 | | - * |
| 5 | + * |
6 | 6 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
7 | 7 | * the License. You may obtain a copy of the License at |
8 | | - * |
| 8 | + * |
9 | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | - * |
| 10 | + * |
11 | 11 | * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
12 | 12 | * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
13 | 13 | * specific language governing permissions and limitations under the License. |
14 | 14 | */ |
15 | 15 | package ubic.basecode.ontology.providers; |
16 | 16 |
|
17 | | -import java.io.IOException; |
18 | | -import java.io.InputStream; |
19 | | - |
20 | | -import ubic.basecode.ontology.OntologyLoader; |
21 | | -import ubic.basecode.ontology.search.OntologyIndexer; |
22 | | - |
23 | 17 | import com.hp.hpl.jena.ontology.OntModel; |
24 | | -import com.hp.hpl.jena.ontology.OntModelSpec; |
| 18 | +import ubic.basecode.ontology.OntologyLoader; |
25 | 19 |
|
26 | 20 | /** |
27 | 21 | * This class has some stuff that's specific to in-memory ontologies. Unlike database backed ontologies we don't use a |
28 | 22 | * pool keeping only one instance of model in memory. |
29 | | - * |
| 23 | + * |
30 | 24 | * @author paul |
31 | 25 | */ |
32 | 26 | public abstract class AbstractOntologyMemoryBackedService extends AbstractOntologyService { |
33 | 27 |
|
34 | | - /** |
35 | | - * For testing! Overrides normal way of loading the ontology. This does not index the ontology unless 'force' is |
36 | | - * true (if there is an existing index, it will be used) |
37 | | - * |
38 | | - * @param is |
39 | | - * @param forceIndex initialize the index. Otherwise it will only be initialized if it doesn't exist. |
40 | | - * @throws IOException |
41 | | - */ |
42 | | - public synchronized void loadTermsInNameSpace( InputStream is, boolean forceIndex ) { |
43 | | - synchronized ( isInitialized ) { |
44 | | - this.indexReady.set( false ); |
45 | | - this.modelReady.set( false ); |
46 | | - this.isInitialized.set( false ); |
47 | | - this.cacheReady.set( false ); |
48 | | - } |
49 | | - |
50 | | - if ( initializationThread.isAlive() ) { |
51 | | - log.warn( this.getOntologyName() + " initialization is already running, trying to cancel ..." ); |
52 | | - initializationThread.cancel(); |
53 | | - |
54 | | - // wait for the thread to die. |
55 | | - int maxWait = 10; |
56 | | - int wait = 0; |
57 | | - while ( initializationThread.isAlive() ) { |
58 | | - try { |
59 | | - Thread.sleep( 5000 ); |
60 | | - log.warn( "Waiting for auto-initialization to stop so manual initialization can begin ..." ); |
61 | | - } catch ( InterruptedException e ) { |
62 | | - // no-op. |
63 | | - } |
64 | | - if ( ++wait >= maxWait ) { |
65 | | - log.error( "Got tired of waiting" ); |
66 | | - break; |
67 | | - } |
68 | | - if ( initializationThread.isInterrupted() ) { |
69 | | - log.warn( "Got interrupt." ); |
70 | | - break; |
71 | | - } |
72 | | - } |
73 | | - } |
74 | | - |
75 | | - if ( this.terms != null ) this.terms.clear(); |
76 | | - if ( this.individuals != null ) this.individuals.clear(); |
77 | | - |
78 | | - this.model = OntologyLoader.loadMemoryModel( is, this.getOntologyUrl(), OntModelSpec.OWL_MEM ); |
79 | | - this.index = OntologyIndexer.getSubjectIndex( getOntologyName() ); |
80 | | - if ( index == null || forceIndex ) { |
81 | | - this.index = OntologyIndexer.indexOntology( getOntologyName(), model, true /* force */ ); |
82 | | - } |
83 | | - |
84 | | - addTerms( OntologyLoader.initialize( this.getOntologyUrl(), model ) ); |
85 | | - |
86 | | - synchronized ( isInitialized ) { |
87 | | - indexReady.set( this.index != null ); |
88 | | - cacheReady.set( true ); |
89 | | - modelReady.set( true ); |
90 | | - isInitialized.set( true ); |
91 | | - } |
92 | | - log.info( this.getClass().getSimpleName() + " ready" ); |
93 | | - } |
94 | | - |
95 | 28 | @Override |
96 | 29 | protected synchronized OntModel loadModel() { |
97 | 30 | return OntologyLoader.loadMemoryModel( this.getOntologyUrl(), this.getOntologyName() ); |
|
0 commit comments