View Javadoc

1   /*
2   Copyright 2011-2014 AGH-UST, http://www.agh.edu.pl
3   Faculty of Computer Science, Electronics and Telecommunications
4   Department of Computer Science 
5   
6   See the NOTICE file distributed with this work for additional
7   information regarding copyright ownership
8   
9   Licensed under the Apache License, Version 2.0 (the "License");
10  you may not use this file except in compliance with the License.
11  You may obtain a copy of the License at
12  
13    http://www.apache.org/licenses/LICENSE-2.0
14  
15  Unless required by applicable law or agreed to in writing, software
16  distributed under the License is distributed on an "AS IS" BASIS,
17  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  See the License for the specific language governing permissions and
19  limitations under the License.
20  */
21  package org.universAAL.ri.gateway.eimanager.impl.importing;
22  
23  import java.util.concurrent.BlockingQueue;
24  
25  import org.universAAL.ri.gateway.eimanager.ImportEntry;
26  import org.universAAL.ri.gateway.eimanager.impl.registry.EIRepoAccessManager;
27  
28  public class ImportProcessExecutor implements Runnable {
29  
30      private BlockingQueue<InternalImportOperation> importQueue;
31  
32      public ImportProcessExecutor(
33  	    final BlockingQueue<InternalImportOperation> queue) {
34  	this.importQueue = queue;
35      }
36  
37      public void run() {
38  	Thread.currentThread()
39  		.setName("Space Gateway :: ImportProcessExecutor");
40  	while (!(Thread.currentThread().isInterrupted())) {
41  	    try {
42  		final InternalImportOperation op = importQueue.take();
43  		this.process(op);
44  	    } catch (InterruptedException e) {
45  		// Set interrupted flag.
46  		Thread.currentThread().interrupt();
47  	    }
48  	}
49      }
50  
51      private void process(final InternalImportOperation op) {
52  	switch (op.getType()) {
53  	case ServiceCaller:
54  	case ContextSubscriber:
55  	case UICaller:
56  	    switch (op.getOp()) {
57  	    case Publish:
58  		EIRepoAccessManager.Instance
59  			.publishImportToRepo(new ImportEntry(op.getMemberId(),
60  				op.getBusMember(), op
61  					.getRemoteRegisteredProxyId(), op, true, ""));
62  		break;
63  
64  	    case Purge:
65  		EIRepoAccessManager.Instance.removeImportFromRepo(op
66  			.getImportEntry());
67  		break;
68  	    }
69  	default:
70  	    // do nothing as only service callers, context subscribers and
71  	    // uicallers can import remote objects;
72  	}
73      }
74  
75  }