<commit_before>/**
 * Copyright (c) <2016> <hasder>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 	
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
*/

package com.eislab.af.translator;


import com.eislab.af.translator.spokes.BaseSpokeConsumer;
import com.eislab.af.translator.spokes.BaseSpokeProvider;
import com.eislab.af.translator.spokes.CoapClient_spoke;
import com.eislab.af.translator.spokes.CoapServer_spoke;
import com.eislab.af.translator.spokes.HttpClient_spoke;
import com.eislab.af.translator.spokes.HttpServer_spoke;
import com.eislab.af.translator.spokes.MqttClient_spoke;
import com.eislab.af.translator.spokes.MqttServer_spoke;
import com.eislab.af.translator.spokes.UaClient_spoke;
import com.eislab.af.translator.spokes.UaServer_spoke;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import java.util.Properties;

interface Translator_hub_i {
	void writeToConsole(String msg);
}

public class Translator_hub extends Observable {//implements Runnable {

	private int id = 0;	

	public static Properties properties;
	public boolean noactivity = false;
	private int fingerprint = 0;
	
	BaseSpokeProvider pSpoke;
	private String  pSpoke_ConsumerName = null;
	private String  pSpoke_ConsumerType = null;
	private String  pSpoke_ConsumerAddress = null;
	private String	pSpokeAddress = null;
	private String	pSpokeIp = null;
	private String	pSpokePort = null;
//	private String 	pSpokePath;		//translationPath;// 	= "*";

	BaseSpokeConsumer cSpoke;
	private String  cSpoke_ProviderName = null;
	private String  cSpoke_ProviderType = null;
	//private String  cSpoke_ProviderAddress = null;
	private String 	cSpoke_ProviderAddress;// 	= "coap://127.0.0.1:5692/";
	private String  cSpoke_ProviderPath;
	
	public Translator_hub(String StubConfiguration)	{
		//this();
		
	}
	
	class SpokeActivityMonitor implements Runnable {
		
		int counter = 0;
		
		public SpokeActivityMonitor() {
			
		}
		
		@Override
		public void run() {
			while(true) {
				// Start a timer
				try {
					//Thread.sleep(600000);//600,000 ms = 10minutes
					Thread.sleep(10000); //10,000 ms = 10 seconds for testing
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				if ( (cSpoke.getLastActivity() > 0) || (pSpoke.getLastActivity() > 0) ){
					cSpoke.clearActivity();
					pSpoke.clearActivity();
					counter = 0;
				} else if (counter < 1){
					counter++;
				} else {
					noactivity = true;//request translation service to release reference to the hub.
					
					pSpoke.close();
					cSpoke.close();
					
					Translator_hub.this.setChanged();
					Translator_hub.this.notifyObservers(Translator_hub.this.getFingerprint());
					
					return;<commit_msg>increase activity timeout to 1 minute (2 minute effective)<commit_after>/**
 * Copyright (c) <2016> <hasder>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 	
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 * 
*/

package com.eislab.af.translator;


import com.eislab.af.translator.spokes.BaseSpokeConsumer;
import com.eislab.af.translator.spokes.BaseSpokeProvider;
import com.eislab.af.translator.spokes.CoapClient_spoke;
import com.eislab.af.translator.spokes.CoapServer_spoke;
import com.eislab.af.translator.spokes.HttpClient_spoke;
import com.eislab.af.translator.spokes.HttpServer_spoke;
import com.eislab.af.translator.spokes.MqttClient_spoke;
import com.eislab.af.translator.spokes.MqttServer_spoke;
import com.eislab.af.translator.spokes.UaClient_spoke;
import com.eislab.af.translator.spokes.UaServer_spoke;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Observable;
import java.util.Observer;
import java.util.Properties;

interface Translator_hub_i {
	void writeToConsole(String msg);
}

public class Translator_hub extends Observable {//implements Runnable {

	private int id = 0;	

	public static Properties properties;
	public boolean noactivity = false;
	private int fingerprint = 0;
	
	BaseSpokeProvider pSpoke;
	private String  pSpoke_ConsumerName = null;
	private String  pSpoke_ConsumerType = null;
	private String  pSpoke_ConsumerAddress = null;
	private String	pSpokeAddress = null;
	private String	pSpokeIp = null;
	private String	pSpokePort = null;
//	private String 	pSpokePath;		//translationPath;// 	= "*";

	BaseSpokeConsumer cSpoke;
	private String  cSpoke_ProviderName = null;
	private String  cSpoke_ProviderType = null;
	//private String  cSpoke_ProviderAddress = null;
	private String 	cSpoke_ProviderAddress;// 	= "coap://127.0.0.1:5692/";
	private String  cSpoke_ProviderPath;
	
	public Translator_hub(String StubConfiguration)	{
		//this();
		
	}
	
	class SpokeActivityMonitor implements Runnable {
		
		int counter = 0;
		
		public SpokeActivityMonitor() {
			
		}
		
		@Override
		public void run() {
			while(true) {
				// Start a timer
				try {
					Thread.sleep(60000);//60,000 ms = 1minute
					//Thread.sleep(10000); //10,000 ms = 10 seconds for testing
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
				if ( (cSpoke.getLastActivity() > 0) || (pSpoke.getLastActivity() > 0) ){
					cSpoke.clearActivity();
					pSpoke.clearActivity();
					counter = 0;
				} else if (counter < 1){
					counter++;
				} else {
					noactivity = true;//request translation service to release reference to the hub.
					
					pSpoke.close();
					cSpoke.close();
					
					Translator_hub.this.setChanged();
					Translator_hub.this.notifyObservers(Translator_hub.this.getFingerprint());
					
					return;
{'fraction_non_alphanumeric': 0.0882856766372381, 'fraction_numerical': 0.01225457899591514, 'mean_word_length': 3.983585029546947, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3863819', 'n_tokens_mistral': 2702, 'n_tokens_neox': 2283, 'n_words': 701}