/** * Method that search the PlatformComponentProfiles tha mach with the parameters * * @param platformComponentType * @param networkServiceType * @param communicationCloudClientIdentity * @return List<PlatformComponentProfile> */ private List<PlatformComponentProfile> searchProfileByCommunicationCloudClientIdentity( PlatformComponentType platformComponentType, NetworkServiceType networkServiceType, String communicationCloudClientIdentity) { /* * Prepare the list */ List<PlatformComponentProfile> temporalList = null; List<PlatformComponentProfile> finalFilteredList = new ArrayList<>(); /* * Switch between platform component type */ switch (platformComponentType) { case COMMUNICATION_CLOUD_SERVER: temporalList = new ArrayList<>( wsCommunicationCloudServer.getRegisteredCommunicationsCloudServerCache().values()); break; case COMMUNICATION_CLOUD_CLIENT: temporalList = new ArrayList<>( wsCommunicationCloudServer.getRegisteredCommunicationsCloudClientCache().values()); break; case NETWORK_SERVICE: temporalList = new ArrayList<>( wsCommunicationCloudServer .getRegisteredNetworkServicesCache() .get(networkServiceType)); break; // Others default: temporalList = wsCommunicationCloudServer .getRegisteredOtherPlatformComponentProfileCache() .get(platformComponentType); break; } /* * Find the component that match with the CommunicationCloudClientIdentity */ for (PlatformComponentProfile platformComponentProfile : temporalList) { if (platformComponentProfile .getCommunicationCloudClientIdentity() .equals(communicationCloudClientIdentity)) { finalFilteredList.add(platformComponentProfile); } } return finalFilteredList; }
/** * Return the primary list from the cache filtered by the platformComponentType or * networkServiceType * * @param platformComponentType * @param networkServiceType * @return List<PlatformComponentProfile> */ public List<PlatformComponentProfile> getPrimaryFilteredListFromCache( PlatformComponentType platformComponentType, NetworkServiceType networkServiceType, String clientIdentityPublicKey) { /* * Get the list */ List<PlatformComponentProfile> list = new ArrayList<>(); /* * Switch between platform component type */ switch (platformComponentType) { case COMMUNICATION_CLOUD_SERVER: if (!wsCommunicationCloudServer.getRegisteredCommunicationsCloudServerCache().isEmpty()) { list = (List<PlatformComponentProfile>) new ArrayList<>( wsCommunicationCloudServer .getRegisteredCommunicationsCloudServerCache() .values()) .clone(); } break; case COMMUNICATION_CLOUD_CLIENT: if (!wsCommunicationCloudServer.getRegisteredCommunicationsCloudClientCache().isEmpty()) { list = (List<PlatformComponentProfile>) new ArrayList<>( wsCommunicationCloudServer .getRegisteredCommunicationsCloudClientCache() .values()) .clone(); } break; case NETWORK_SERVICE: if (wsCommunicationCloudServer .getRegisteredNetworkServicesCache() .containsKey(networkServiceType) && !wsCommunicationCloudServer .getRegisteredNetworkServicesCache() .get(networkServiceType) .isEmpty()) { list = (List<PlatformComponentProfile>) new ArrayList<>( wsCommunicationCloudServer .getRegisteredNetworkServicesCache() .get(networkServiceType)) .clone(); } break; // Others default: if (wsCommunicationCloudServer .getRegisteredOtherPlatformComponentProfileCache() .containsKey(platformComponentType) && !wsCommunicationCloudServer .getRegisteredOtherPlatformComponentProfileCache() .get(platformComponentType) .isEmpty()) { list = (List<PlatformComponentProfile>) new ArrayList<>( wsCommunicationCloudServer .getRegisteredOtherPlatformComponentProfileCache() .get(platformComponentType)) .clone(); } break; } /* * Remove the requester from the list */ Iterator<PlatformComponentProfile> iterator = list.iterator(); while (iterator.hasNext()) { PlatformComponentProfile platformComponentProfileRegistered = iterator.next(); if (platformComponentProfileRegistered .getCommunicationCloudClientIdentity() .equals(clientIdentityPublicKey)) { System.out.println( "ComponentRegisteredListWebService - removing =" + platformComponentProfileRegistered.getName()); iterator.remove(); } } return list; }
/** * (non-Javadoc) * * @see Service#start() */ @Override public void start() { try { /* * Validate required resources */ // validateInjectedResources(); if (disableServerFlag) { System.out.println( "WsCommunicationsServerCloudPluginRoot - Local Server is Disable, no started"); return; } System.out.println("WsCommunicationsServerCloudPluginRoot - Starting plugin"); /* * Get all network interfaces of the device */ Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces(); while (interfaces.hasMoreElements()) { NetworkInterface networkInterface = interfaces.nextElement(); /** If not a loopback interfaces (127.0.0.1) and is active */ if (!networkInterface.isLoopback() && networkInterface.isUp()) { /* * Get his inet addresses */ Enumeration<InetAddress> addresses = networkInterface.getInetAddresses(); /* * Create a cloud service for each ip */ for (InetAddress address : Collections.list(addresses)) { /** look only for ipv4 addresses */ if (address instanceof Inet6Address) { continue; } WebSocketImpl.DEBUG = false; InetSocketAddress inetSocketAddress = new InetSocketAddress(address, WsCommunicationCloudServer.DEFAULT_PORT); wsCommunicationCloudServer = new WsCommunicationCloudServer(inetSocketAddress); wsCommunicationCloudServer.registerFermatPacketProcessor( new ComponentRegistrationRequestPacketProcessor()); wsCommunicationCloudServer.registerFermatPacketProcessor( new ComponentConnectionRequestPacketProcessor()); wsCommunicationCloudServer.registerFermatPacketProcessor( new DiscoveryComponentConnectionRequestPacketProcessor()); wsCommunicationCloudServer.registerFermatPacketProcessor( new RequestListComponentRegisterPacketProcessor()); wsCommunicationCloudServer.start(); /* * Start the ping agent */ wsCommunicationsCloudServerPingAgent = new WsCommunicationsCloudServerPingAgent(wsCommunicationCloudServer); wsCommunicationsCloudServerPingAgent.start(); System.out.println( "New CommunicationChannelAddress linked on " + networkInterface.getName()); System.out.println("Host = " + inetSocketAddress.getHostString()); System.out.println("Port = " + inetSocketAddress.getPort()); System.out.println( "Communication Service Manager on " + networkInterface.getName() + " started."); break; } } } /* * Create and start the restlet server */ RestletCommunicationCloudServer rlCommunicationCloudServer = new RestletCommunicationCloudServer(wsCommunicationCloudServer); rlCommunicationCloudServer.start(); /* * Start the socket to handle the request of Component Registered List */ // SocketServerInitialization socketServerInitialization =new // SocketServerInitialization(wsCommunicationCloudServer); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } /* * Set the new status of the service */ this.serviceStatus = ServiceStatus.STARTED; }