1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.universAAL.ri.gateway.eimanager.impl.importing;
22
23 import java.io.IOException;
24 import java.util.HashSet;
25 import java.util.Set;
26
27 import org.universAAL.middleware.container.ModuleContext;
28 import org.universAAL.middleware.service.ServiceCall;
29 import org.universAAL.middleware.service.ServiceCallee;
30 import org.universAAL.middleware.service.ServiceResponse;
31 import org.universAAL.middleware.service.owls.profile.ServiceProfile;
32 import org.universAAL.ri.gateway.eimanager.impl.ProxyBusMember;
33
34 public class ProxyServiceCallee extends ProxyBusMember {
35
36 private ServiceCallee callee;
37 private Set<ServiceProfile> profilesSet;
38
39 public ProxyServiceCallee(final ServiceProfile[] realizedServices,
40 final ImportedProxyManager manager, final String targetId, final String remoteBusMemberId,
41 final ModuleContext mc) {
42 super(manager, targetId, remoteBusMemberId, mc);
43 profilesSet = new HashSet<ServiceProfile>();
44 for (ServiceProfile profile : realizedServices) {
45 profilesSet.add(profile);
46 }
47 callee = new CustomServiceCalee(mc, realizedServices);
48 }
49
50 @Override
51 public void removeProxy() {
52 callee.close();
53 }
54
55 @Override
56 public String getId() {
57 return callee.getMyID();
58 }
59
60 public void refreshProfiles(final ServiceProfile[] profiles) {
61 ServiceCallee old = callee;
62 callee = new CustomServiceCalee(mc, profiles);
63 old.close();
64
65 profilesSet.clear();
66 for (ServiceProfile profile : profiles) {
67 profilesSet.add(profile);
68 }
69
70 }
71
72 public Set<ServiceProfile> getProfilesSet() {
73 return profilesSet;
74 }
75
76 public void setProfilesSet(Set<ServiceProfile> profilesSet) {
77 this.profilesSet = profilesSet;
78 }
79
80 private class CustomServiceCalee extends ServiceCallee {
81 protected CustomServiceCalee(final ModuleContext context,
82 final ServiceProfile[] realizedServices) {
83 super(context, realizedServices);
84 }
85
86 @Override
87 public ServiceResponse handleCall(final ServiceCall call) {
88 ServiceResponse response;
89 try {
90 response = ((ImportedProxyManager) getManager())
91 .realizeRemoteServiceRequest(targetId,
92 call, remoteBusMemberId);
93 return response;
94 } catch (IOException e) {
95
96 e.printStackTrace();
97 } catch (ClassNotFoundException e) {
98
99 e.printStackTrace();
100 }
101 return null;
102 }
103
104 @Override
105 public void communicationChannelBroken() {
106 }
107 }
108
109 }