gt:             if (emitterFound && receiverFound) {
context: /*******************************************************************************
   * Copyright (c) 2016, 2017 Eurotech and/or its affiliates and others
   *
   * 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:
   *  Eurotech
   *  Amit Kumar Mondal
   *
   *******************************************************************************/
  package org.eclipse.kura.internal.wire;
  
  import static java.util.Objects.isNull;
  import static java.util.Objects.nonNull;
  import static java.util.Objects.requireNonNull;
  import static org.eclipse.kura.internal.wire.WireServiceOptions.SEPARATOR;
  import static org.osgi.service.wireadmin.WireConstants.WIREADMIN_CONSUMER_PID;
  import static org.osgi.service.wireadmin.WireConstants.WIREADMIN_PRODUCER_PID;
  
  import java.util.Collections;
  import java.util.Dictionary;
  import java.util.Iterator;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import org.eclipse.kura.KuraErrorCode;
  import org.eclipse.kura.KuraException;
  import org.eclipse.kura.configuration.ComponentConfiguration;
  import org.eclipse.kura.configuration.SelfConfiguringComponent;
  import org.eclipse.kura.core.configuration.ComponentConfigurationImpl;
  import org.eclipse.kura.core.configuration.metatype.Tocd;
  import org.eclipse.kura.localization.LocalizationAdapter;
  import org.eclipse.kura.localization.resources.WireMessages;
  import org.eclipse.kura.util.collection.CollectionUtil;
  import org.eclipse.kura.wire.WireComponent;
  import org.eclipse.kura.wire.WireConfiguration;
  import org.eclipse.kura.wire.WireHelperService;
  import org.eclipse.kura.wire.WireService;
  import org.osgi.framework.InvalidSyntaxException;
  import org.osgi.service.component.ComponentContext;
  import org.osgi.service.wireadmin.Wire;
  import org.osgi.service.wireadmin.WireAdmin;
  import org.osgi.util.tracker.ServiceTracker;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
  
  /**
   * The Class {@link WireServiceImpl} implements {@link WireService}
   */
  public final class WireServiceImpl implements SelfConfiguringComponent, WireService {
  
      /** Configuration PID Property */
      private static final String CONF_PID = "org.eclipse.kura.wire.WireService";
  
      private static final Logger logger = LoggerFactory.getLogger(WireServiceImpl.class);
  
      private static final WireMessages message = LocalizationAdapter.adapt(WireMessages.class);
  
      /** The service component properties. */
      private Map<String, Object> properties;
  
      private volatile WireAdmin wireAdmin;
  
      private ServiceTracker<WireComponent, WireComponent> wireComponentServiceTracker;
  
      private WireComponentTrackerCustomizer wireComponentTrackerCustomizer;
  
      private final Set<WireConfiguration> wireConfigs;
  
      private volatile WireHelperService wireHelperService;
  
      private WireServiceOptions wireServiceOptions;
  
      public WireServiceImpl() {
          final Set<WireConfiguration> set = CollectionUtil.newHashSet();
          this.wireConfigs = Collections.synchronizedSet(set);
      }
  
      /**
       * OSGi service component callback while activation
       *
       * @param componentContext
       *            the component context
       * @param properties
       *            the service properties
       */
      protected void activate(final ComponentContext componentContext, final Map<String, Object> properties) {
          logger.debug(message.activatingWireService());
          extractProperties(properties);
          try {
              this.wireComponentTrackerCustomizer = new WireComponentTrackerCustomizer(
                      componentContext.getBundleContext(), this);
              this.wireComponentServiceTracker = new ServiceTracker<>(componentContext.getBundleContext(),
                      WireComponent.class, this.wireComponentTrackerCustomizer);
              this.wireComponentServiceTracker.open();
          } catch (final InvalidSyntaxException exception) {
              logger.error(message.error(), exception);
          }
          createWires();
          logger.debug(message.activatingWireServiceDone());
      }
  
      /**
       * Binds the {@link WireAdmin} dependency
       *
       * @param wireAdmin
       *            the new {@link WireAdmin} service dependency
       */
      public void bindWireAdmin(final WireAdmin wireAdmin) {
          if (isNull(this.wireAdmin)) {
              this.wireAdmin = wireAdmin;
          }
      }
  
      /**
       * Binds the {@link WireHelperService}.
       *
       * @param wireHelperService
       *            the new {@link WireHelperService}
       */
      public void bindWireHelperService(final WireHelperService wireHelperService) {
          if (isNull(this.wireHelperService)) {
              this.wireHelperService = wireHelperService;
          }
      }
  
      /**
       * Checks for existence of {@link WireAdmin}'s {@link Wire} instance between the
       * provided Emitter Service PID and Receiver Service PID
       *
       * @param emitterServicePid
       *            Wire Emitter Service PID {@code service.pid}
       * @param receiverServicePid
       *            Wire Receiver Service PID {@code service.pid}
       * @return true if exists, otherwise false
       * @throws InvalidSyntaxException
       *             If the {@link Wire} filter has an invalid LDAP syntax ({@code null} accepted}
       * @throws NullPointerException
       *             if any of the provided arguments is null
       */
      private boolean checkWireExistence(final String emitterServicePid, final String receiverServicePid)
              throws InvalidSyntaxException {
          requireNonNull(emitterServicePid, message.emitterServicePidNonNull());
          requireNonNull(receiverServicePid, message.receiverServicePidNonNull());
  
          boolean found = false;
          final Wire[] wires = this.wireAdmin.getWires(null);
          if (nonNull(wires)) {
              for (final Wire w : wires) {
                  final Dictionary<?, ?> props = w.getProperties();
                  if (props.get(WIREADMIN_PRODUCER_PID).equals(emitterServicePid)
                          && props.get(WIREADMIN_CONSUMER_PID).equals(receiverServicePid)) {
                      found = true;
                      break;
                  }
              }
          }
          return found;
      }
  
      /**
       * Creates the {@link WireAdmin}'s {@link Wire} instance between the provided
       * Emitter PID and Receiver PID and sets the created {@link Wire} instance to the
       * provided {@link WireConfiguration} instance
       *
       * @param conf
       *            the {@link WireConfiguration} instance
       * @param emitterPid
       *            Wire Emitter PID
       * @param receiverPid
       *            Wire Receiver PID
       * @throws NullPointerException
       *             if any of the arguments is null
       */
      private void createConfiguration(final WireConfiguration conf, final String emitterPid, final String receiverPid) {
          requireNonNull(conf, message.wireConfigurationNonNull());
          requireNonNull(emitterPid, message.emitterPidNonNull());
          requireNonNull(receiverPid, message.receiverPidNonNull());
  
          final String emitterServicePid = this.wireHelperService.getServicePid(emitterPid);
          final String receiverServicePid = this.wireHelperService.getServicePid(receiverPid);
          if (nonNull(emitterServicePid) && nonNull(receiverServicePid) && isNull(conf.getWire())) {
              try {
                  final boolean found = checkWireExistence(emitterServicePid, receiverServicePid);
                  if (!found) {
                      final Wire wire = this.wireAdmin.createWire(emitterServicePid, receiverServicePid, null);
                      conf.setWire(wire);
                  }
              } catch (final InvalidSyntaxException e) {
                  logger.error(message.errorCreatingWires(), e);
              }
          }
      }
  
      /** {@inheritDoc} */
      @Override
      public WireConfiguration createWireConfiguration(final String emitterPid, final String receiverPid)
              throws KuraException {
          requireNonNull(emitterPid, message.emitterPidNonNull());
          requireNonNull(receiverPid, message.receiverPidNonNull());
  
          logger.info(message.creatingWire(emitterPid, receiverPid));
          WireConfiguration conf = null;
          if (!emitterPid.equals(receiverPid)) {
              final String emitterServicePid = this.wireHelperService.getServicePid(emitterPid);
              final String receiverServicePid = this.wireHelperService.getServicePid(receiverPid);
              if (isNull(emitterServicePid) || isNull(receiverServicePid)) {
                  throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, message.componentPidsNull());
              }
              if (!(this.wireHelperService.isEmitter(emitterPid) || this.wireHelperService.isReceiver(receiverPid))) {
                  throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR, message.componentsNotApplicable());
              }
              conf = new WireConfiguration(emitterPid, receiverPid);
              final Wire wire = this.wireAdmin.createWire(emitterServicePid, receiverServicePid, null);
              if (nonNull(wire)) {
                  conf.setWire(wire);
                  this.wireConfigs.add(conf);
              }
              logger.info(message.creatingWireDone(emitterPid, receiverPid));
          }
          return conf;
      }
  
      /**
       * Create the wires based on the provided wire configurations
       */
      synchronized void createWires() {
          logger.debug(message.creatingWires());
          final List<WireConfiguration> cloned = CollectionUtil.newArrayList();
          for (final WireConfiguration wc : this.wireConfigs) {
              final WireConfiguration wireConf = new WireConfiguration(wc.getEmitterPid(), wc.getReceiverPid());
              wireConf.setFilter(wc.getFilter());
              cloned.add(wireConf);
          }
          for (final WireConfiguration wireConfig : cloned) {
              final String emitterPid = wireConfig.getEmitterPid();
              final String receiverPid = wireConfig.getReceiverPid();
  
              final boolean emitterFound = this.wireComponentTrackerCustomizer.getWireEmitters().contains(emitterPid);
              final boolean receiverFound = this.wireComponentTrackerCustomizer.getWireReceivers().contains(receiverPid);
  
  