/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package TCM_MPIv2.CheckClasses;
import TCM_MPI.CheckClasses.IStopable;
import TCM_MPI_UTILS.Message.TcmMpiBasicPackage;
import TCM_MPI_UTILS.Socket.Interfaces.ISocketTcm;
import TCM_MPIv2.Buffer.BufferInfov2;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
/**
*
* @author dev
*/
public class CheckDatav2_JvmTcp implements Runnable , IStopable{
private ISocketTcm _SOCKET;
private BufferInfov2 _BUFFER;
private ExecutorService _POOL;
private AtomicBoolean BOOL = new AtomicBoolean(true);
public CheckDatav2_JvmTcp(ISocketTcm JVM_SKT,BufferInfov2 N_BUFFER,ExecutorService POOL){
this._SOCKET = JVM_SKT;
this._BUFFER = N_BUFFER;
this._POOL = POOL;
}
public CheckDatav2_JvmTcp(ISocketTcm JVM_SKT,BufferInfov2 N_BUFFER){
this._SOCKET = JVM_SKT;
this._BUFFER = N_BUFFER;
this._POOL = Executors.newSingleThreadExecutor();
}
public void CheckData(){
TcmMpiBasicPackage pkg = (TcmMpiBasicPackage) this._SOCKET.ReceiveMpiPackage();
if(pkg == null){
return;
}
this._POOL.submit(new TreatPkgData(pkg));
}
@Override
public void run() {
while(this.BOOL.get()){
try{
CheckData();
}catch(Exception ex){
}
}
this._POOL.shutdown();
}
@Override
public void SendStopCommand() {
this.BOOL.set(false);
}
@Override
public boolean IsStoped() {
return (this.BOOL.get() == false);
}
class TreatPkgData implements Runnable{
private TcmMpiBasicPackage pkg;
public TreatPkgData(TcmMpiBasicPackage pkg){
this.pkg = pkg;
}
@Override
public void run() {
_BUFFER.InsertData(this.pkg.getPROC_ID(),this.pkg.getTYPE_ID(), this.pkg);
}
}
}