Project

General

Profile

« Previous | Next » 

Revision 7776

Added by Jing Tao over 11 years ago

Use another thread in the Servlet init method to wait hazelcast.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/ApplicationController.java
41 41
 * @author tao
42 42
 *
43 43
 */
44
public class ApplicationController {
44
public class ApplicationController implements Runnable {
45 45
    
46 46
    private static String SOLRINDEXES = "solrIndexes";
47 47
    private static short FIRST = 0;
48 48

  
49 49
    private List<SolrIndex> solrIndexes = null;
50
    //private List<SystemMetadataEventListener> sysmetaListeners = new ArrayList<SystemMetadataEventListener>();
50
    private List<SystemMetadataEventListener> sysmetaListeners = new ArrayList<SystemMetadataEventListener>();
51 51
    private static ApplicationContext context = null;
52 52
    private String springConfigFile = "src/main/resources/index-processor-context.xml";
53 53
    Log log = LogFactory.getLog(ApplicationController.class);
......
95 95
			// start listening for events
96 96
        	SystemMetadataEventListener smel = new SystemMetadataEventListener();
97 97
        	smel.setSolrIndex(solrIndex);
98
        	smel.start();
99
        	//sysmetaListeners.add(smel);
98
        	sysmetaListeners.add(smel);
99
        	//smel.start();
100 100
        }
101 101
        
102 102
    }
......
131 131
    /**
132 132
     * Start to generate indexes for those haven't been indexed in another thread.
133 133
     */
134
    public void startIndex() {
134
    private void startIndex() {
135 135
        SolrIndex index = solrIndexes.get(FIRST);
136 136
        //SystemMetadataEventListener listener = sysmetaListeners.get(FIRST);
137 137
        IndexGenerator generator = new IndexGenerator(index);
138 138
        Thread indexThread = new Thread(generator);
139 139
        indexThread.start();
140 140
    }
141
    
142
    /**
143
     * Start the system metadata listener
144
     */
145
    public void startSysmetaListener() {
146
        if(sysmetaListeners != null) {
147
            //only expects one listener.
148
            for(SystemMetadataEventListener listener : sysmetaListeners) {
149
                if(listener != null) {
150
                    listener.start();
151
                }
152
            }
153
        }
154
    }
155
    
156
    /**
157
     * It will start system metadata event listener first. Then to generate indexes for those haven't been indexed in another thread.
158
     */
159
    public void run() {
160
        startSysmetaListener();
161
        startIndex();//it will create another thread.
162
    }
141 163
}
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/MetacatIndexServlet.java
85 85
        ApplicationController controller = null;
86 86
        try {
87 87
             controller = new ApplicationController(FILEPREFIX + url.getFile());
88
             //Start SystemmetadataEventListener and to generate indexes for those haven't been indexed in another thread
89
             Thread sysListenerAndindexThread = new Thread(controller);
90
             sysListenerAndindexThread.start();
88 91
        } catch (Exception e) {
89 92
            throw new ServletException(e.getMessage());
90 93
        }
91
        
92
        controller.startIndex();//Start to generate indexes for those haven't been indexed in another thread
94
       
95
        //controller.startIndex();//Start to generate indexes for those haven't been indexed in another thread
93 96
        //List<SolrIndex> list = controller.getSolrIndexes();
94 97
        //System.out.println("++++++++++++++++++++++++------------------- the size is  "+list.size());
95 98
    }

Also available in: Unified diff