Skip to main content
summaryrefslogtreecommitdiffstats
blob: 86247564953bc72fa81147ca9d745fe85cdc9e29 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/
package org.eclipse.osee.ote.service;

import java.util.logging.Level;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.messaging.EndpointReceive;
import org.eclipse.osee.framework.messaging.EndpointSend;
import org.eclipse.osee.framework.messaging.MessagingGateway;
import org.eclipse.osee.ote.service.core.OteClientEndpointSend;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import org.osgi.util.tracker.ServiceTracker;

/**
 * @author Andrew M. Finkbeiner
 */
public class MessagingGatewayBindTracker extends ServiceTracker {

   private final EndpointSend send;
   private final EndpointReceive receive;

   public MessagingGatewayBindTracker(BundleContext context, EndpointSend send, EndpointReceive receive) {
      super(context, MessagingGateway.class.getName(), null);
      this.send = send;
      this.receive = receive;
   }

   @Override
   public Object addingService(ServiceReference reference) {
      Object obj = context.getService(reference);
      MessagingGateway messagingGateway = (MessagingGateway) obj;
      if (!messagingGateway.bind(send)) {
         OseeLog.logf(Activator.class, Level.SEVERE,
            "Unable to bind %s to the MessagingGateway.", send.toString());
      }
      if (!messagingGateway.bind(receive)) {
         OseeLog.logf(Activator.class, Level.SEVERE,
            "Unable to bind %s to the MessagingGateway.", receive.toString());
      }
      if (!messagingGateway.bindSendProtocol(OteClientEndpointSend.OTE_CLIENT_SEND_PROTOCOL, send)) {
         OseeLog.logf(Activator.class, Level.SEVERE, 
            "Unable to bind %s to %s through the MessagingGateway.",
            OteClientEndpointSend.OTE_CLIENT_SEND_PROTOCOL.toString(), send.toString());
      }
      return super.addingService(reference);
   }

   @Override
   public void removedService(ServiceReference reference, Object service) {
      Object obj = context.getService(reference);
      MessagingGateway messagingGateway = (MessagingGateway) obj;
      if (!messagingGateway.unbindSendProtocol(OteClientEndpointSend.OTE_CLIENT_SEND_PROTOCOL, send)) {
         OseeLog.logf(Activator.class, Level.SEVERE, 
            "Unable to bind %s to %s through the MessagingGateway.",
            OteClientEndpointSend.OTE_CLIENT_SEND_PROTOCOL.toString(), send.toString());
      }
      if (!messagingGateway.unbind(send)) {
         OseeLog.logf(Activator.class, Level.SEVERE,
            "Unable to unbind %s to the MessagingGateway.", send.toString());
      }
      if (!messagingGateway.unbind(receive)) {
         OseeLog.logf(Activator.class, Level.SEVERE,
            "Unable to bind %s to the MessagingGateway.", receive.toString());
      }
      super.removedService(reference, service);
   }

}

Back to the top