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;
22  
23  import java.io.IOException;
24  import java.util.Set;
25  import java.util.concurrent.ArrayBlockingQueue;
26  import java.util.concurrent.BlockingQueue;
27  
28  import org.universAAL.middleware.bus.member.BusMember;
29  import org.universAAL.middleware.service.ServiceCall;
30  import org.universAAL.middleware.service.ServiceResponse;
31  import org.universAAL.middleware.ui.UIRequest;
32  import org.universAAL.ri.gateway.communicator.service.GatewayCommunicator;
33  import org.universAAL.ri.gateway.eimanager.ExportExecutor;
34  import org.universAAL.ri.gateway.eimanager.ExportManager;
35  import org.universAAL.ri.gateway.eimanager.ExportPremise;
36  import org.universAAL.ri.gateway.eimanager.impl.exporting.ExportProcessExecutor;
37  import org.universAAL.ri.gateway.eimanager.impl.exporting.ExportedProxyManager;
38  import org.universAAL.ri.gateway.eimanager.impl.exporting.InternalExportOperation;
39  import org.universAAL.ri.gateway.eimanager.impl.exporting.ProxyRegistration;
40  import org.universAAL.ri.gateway.eimanager.impl.importing.ImportRequest;
41  
42  public class ExportManagerImpl implements ExportManager, ExportExecutor{
43      
44      private ExportProcessExecutor exportExecutor;
45      private Thread exportThread;
46      
47      private ExportedProxyManager manager;
48      
49      private Set<ExportPremise> exportPremises;
50      
51      private BlockingQueue<InternalExportOperation> busMembersToExport;
52      
53      private GatewayCommunicator communicator;
54      
55      public ExportManagerImpl(GatewayCommunicator communicator){
56  	this.communicator = communicator;
57  	
58  	busMembersToExport = new ArrayBlockingQueue<InternalExportOperation>(5);
59  	
60  	exportExecutor = new ExportProcessExecutor(busMembersToExport);
61  	exportThread = new Thread(exportExecutor);
62  	exportThread.start();
63  	
64  	manager = new ExportedProxyManager(communicator);
65      }
66     
67      public void shutdown(){
68  	exportThread.interrupt();
69      }
70      /*
71       * Methods for tracing registered BusMembers
72       * */
73      public void memberAdded(BusMember member) {
74  	
75      }
76      
77      public void memberRemoved(BusMember member){
78  	
79      }
80  
81      public void addExportPremise(ExportPremise premise){
82  	exportPremises.add(premise);
83      }
84      
85      public void removeExportPremise(ExportPremise premise){
86  	exportPremises.remove(premise);
87      }
88  
89      public void exportBusMemberForRemote(BusMember sourceMember) {
90  	// TODO implement in next release
91      }
92  
93      public void removeExportedBusMember(BusMember sourceMember) {
94  	// TODO implement in next release
95  	
96      }
97  
98      public ServiceResponse sendServiceRequest(String sourceId, ServiceCall call, String memberId) {
99  	ServiceResponse response = manager.sendServiceRequest(sourceId, call, memberId);
100 	if (response == null){
101 	    throw new RuntimeException("response == null");
102 	}
103 	return response;
104     }
105 
106     public void sendUIRequest(String sourceId, UIRequest request) {
107 	manager.sendUIRequest(sourceId, request);
108     }
109 
110     public ProxyRegistration registerProxies(ImportRequest request) throws IOException, ClassNotFoundException {
111 	return manager.registerProxies(request);
112     }
113 
114     public void unregisterProxies(ImportRequest request) {
115 	manager.unregisterProxies(request);
116     }
117 }