www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,119 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import java.util.concurrent.ArrayBlockingQueue;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SaveScoreProcessor {
|
||||
private static boolean debug = true;
|
||||
|
||||
private static SaveScoreProcessor instance;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> taskQueue;
|
||||
|
||||
private final ExecutorService executor;
|
||||
|
||||
private int activeConsumers = 0;
|
||||
|
||||
private static ApplParmFull ap;
|
||||
|
||||
private static int numThreads = 10;
|
||||
|
||||
public static final String TAG_THREAD_MSG = "SAVE_SCORE_TASK";
|
||||
|
||||
private static final int QUEUE_CAPACITY = 200;
|
||||
|
||||
private SaveScoreProcessor(int numThreads) {
|
||||
this.taskQueue = new ArrayBlockingQueue<>(200);
|
||||
this.executor = new ThreadPoolExecutor(numThreads, numThreads, 60L, TimeUnit.SECONDS, new ArrayBlockingQueue<>(200), new ThreadPoolExecutor.AbortPolicy());
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
this.executor.submit(new SaveScoreTask(this.taskQueue, null, null));
|
||||
}
|
||||
|
||||
public static synchronized SaveScoreProcessor getInstance(ApplParmFull l_ap, int numThreads) {
|
||||
ap = l_ap;
|
||||
SaveScoreProcessor.numThreads = numThreads;
|
||||
if (instance == null)
|
||||
instance = new SaveScoreProcessor(numThreads);
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static synchronized SaveScoreProcessor getInstance(ApplParmFull l_ap) {
|
||||
ap = l_ap;
|
||||
return instance;
|
||||
}
|
||||
|
||||
public synchronized void aggiungiInCoda(ApplParmFull ap, JsonObject jo) {
|
||||
try {
|
||||
if (!this.taskQueue.offer(new SaveScoreTask(this.taskQueue, ap, jo), 1L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(debug, "Coda piena, impossibile aggiungere il task.");
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "Task aggiunto alla coda.");
|
||||
if (this.activeConsumers < numThreads) {
|
||||
DBAdapter.printDebug(debug, "Avvio di un nuovo thread consumer. Consumer attivi: " + this.activeConsumers);
|
||||
this.executor.submit(new SaveScoreTask(this.taskQueue, null, null));
|
||||
this.activeConsumers++;
|
||||
}
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", "AggiungiInCoda. activeConsumers: " + this.activeConsumers + " " +
|
||||
getInstance(ap).getDescProcess());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
DBAdapter.printDebug(debug, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
} catch (Exception e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(debug, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
this.executor.shutdown();
|
||||
try {
|
||||
if (!this.executor.awaitTermination(60L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(debug, "Forzando l'arresto dei thread...");
|
||||
this.executor.shutdownNow();
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
this.executor.shutdownNow();
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
instance = null;
|
||||
DBAdapter.printDebug(debug, "SaveScoreProcessor è stato arrestato e l'istanza è stata resettata.");
|
||||
}
|
||||
|
||||
public final int getQueueSize() {
|
||||
return this.taskQueue.size();
|
||||
}
|
||||
|
||||
public boolean isIdle() {
|
||||
if (this.executor == null)
|
||||
return false;
|
||||
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)this.executor;
|
||||
return (this.taskQueue.isEmpty() && threadPoolExecutor.getActiveCount() == 0);
|
||||
}
|
||||
|
||||
public String getDescProcess() {
|
||||
if (this.executor == null)
|
||||
return "Executor non attivo";
|
||||
ThreadPoolExecutor threadPoolExecutor = (ThreadPoolExecutor)this.executor;
|
||||
return "Active thread: " + threadPoolExecutor.getActiveCount() + " task queue len: " + this.taskQueue.size();
|
||||
}
|
||||
|
||||
public synchronized void decrementActiveConsumers() {
|
||||
if (this.activeConsumers > 0)
|
||||
this.activeConsumers--;
|
||||
DBAdapter.printDebug(debug, "Consumer attivi decrementati: " + this.activeConsumers);
|
||||
if (this.activeConsumers > 0)
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", "Consumer attivi decrementati: " + this.activeConsumers + " " +
|
||||
getInstance(ap).getDescProcess());
|
||||
}
|
||||
|
||||
public synchronized int getActiveConsumers() {
|
||||
return this.activeConsumers;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScoreZoo;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
public class SaveScoreTask implements Runnable {
|
||||
private static boolean debug = true;
|
||||
|
||||
private final JsonObject jo;
|
||||
|
||||
private final ApplParmFull ap;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> queue;
|
||||
|
||||
public JsonObject getJsonObject() {
|
||||
return this.jo;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
String tag = DBAdapter.getTimeNameForFileUpload() + " ";
|
||||
SaveScoreTask sst = this.queue.take();
|
||||
StatusMsg.updateMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK", tag + "Elaborazione iniziata per task saveScoreResponse. " + tag);
|
||||
DBAdapter.printDebug(debug, "Elaborazione iniziata per task: " + SaveScoreProcessor.getInstance(this.ap).getDescProcess());
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(sst.getApplParmFull());
|
||||
ResParm rp = fsz.saveScoreResponse(sst.getJsonObject());
|
||||
StatusMsg.updateMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK", tag + "Elaborazione conclusa per task saveScoreResponse. qs: " + tag);
|
||||
Evento.inviaNotificaRemotaWww(getApplParmFull(), 0L);
|
||||
synchronized (SaveScoreProcessor.class) {
|
||||
SaveScoreProcessor.getInstance(this.ap).decrementActiveConsumers();
|
||||
}
|
||||
if (SaveScoreProcessor.getInstance(this.ap).isIdle())
|
||||
StatusMsg.deleteMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("SaveScoreTask interrotto: " + e.getMessage());
|
||||
} finally {
|
||||
synchronized (SaveScoreProcessor.class) {
|
||||
SaveScoreProcessor.getInstance(this.ap).decrementActiveConsumers();
|
||||
}
|
||||
if (SaveScoreProcessor.getInstance(this.ap).isIdle())
|
||||
StatusMsg.deleteMsgByTag(getApplParmFull(), "SAVE_SCORE_TASK");
|
||||
}
|
||||
}
|
||||
|
||||
public SaveScoreTask(BlockingQueue<SaveScoreTask> queue, ApplParmFull ap, JsonObject jo) {
|
||||
this.queue = queue;
|
||||
this.jo = jo;
|
||||
this.ap = ap;
|
||||
}
|
||||
|
||||
public ApplParmFull getApplParmFull() {
|
||||
return this.ap;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.ApplParmFull;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.FaceScoreZoo;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
@Deprecated
|
||||
public class SaveScoreWorker implements Runnable {
|
||||
private static boolean debug = true;
|
||||
|
||||
private final BlockingQueue<SaveScoreTask> queue;
|
||||
|
||||
private static ApplParmFull ap;
|
||||
|
||||
public SaveScoreWorker(ApplParmFull l_ap, BlockingQueue<SaveScoreTask> queue) {
|
||||
ap = l_ap;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
String tag = DBAdapter.getTimeNameForFileUpload() + " ";
|
||||
SaveScoreTask sst = this.queue.take();
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", tag + "Elaborazione iniziata per task saveScoreResponse. qs: " + tag);
|
||||
DBAdapter.printDebug(debug, "Elaborazione iniziata per task: ");
|
||||
FaceScoreZoo fsz = new FaceScoreZoo(sst.getApplParmFull());
|
||||
ResParm rp = fsz.saveScoreResponse(sst.getJsonObject());
|
||||
if (SaveScoreProcessor.getInstance(ap, 30).getQueueSize() > 1) {
|
||||
StatusMsg.updateMsgByTag(ap, "SAVE_SCORE_TASK", tag + "Elaborazione conclusa per task saveScoreResponse. qs: " + tag);
|
||||
continue;
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(ap, "SAVE_SCORE_TASK");
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("SelfieWorker interrotto: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,96 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.face.Selfie;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfieProcessor {
|
||||
private static SelfieProcessor instance;
|
||||
|
||||
private final BlockingQueue<Selfie> queue;
|
||||
|
||||
private final ThreadPoolExecutor executor;
|
||||
|
||||
private final ScheduledExecutorService monitor;
|
||||
|
||||
private static int numThreads = 10;
|
||||
|
||||
private static final boolean debug = true;
|
||||
|
||||
private SelfieProcessor(int numThreads) {
|
||||
this.queue = new LinkedBlockingQueue<>();
|
||||
this.executor = new ThreadPoolExecutor(numThreads, numThreads, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), new ThreadFactory() {
|
||||
public Thread newThread(Runnable r) {
|
||||
Thread t = new Thread(r);
|
||||
t.setUncaughtExceptionHandler((thread, e) -> {
|
||||
DBAdapter.printDebug("ERRORE!!!!!!! Thread " +
|
||||
thread.getName() + " terminato con errore: " + e.getMessage());
|
||||
SelfieProcessor.this.executor.submit(new SelfieWorker(SelfieProcessor.this.queue));
|
||||
DBAdapter.printDebug(true, "Riavviato nuovo thread!");
|
||||
});
|
||||
return t;
|
||||
}
|
||||
});
|
||||
for (int i = 0; i < numThreads; i++) {
|
||||
DBAdapter.printDebug(true, "Avviato selfieworker n. " + i);
|
||||
this.executor.submit(new SelfieWorker(this.queue));
|
||||
}
|
||||
this.monitor = Executors.newSingleThreadScheduledExecutor();
|
||||
this.monitor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
int queueSize = this.queue.size();
|
||||
int activeThreads = this.executor.getActiveCount();
|
||||
int totalThreads = this.executor.getPoolSize();
|
||||
DBAdapter.printDebug(true, "SelfieProcessor Monitor ====> Coda attuale: " + queueSize + " | Thread attivi: " + activeThreads + " su " + totalThreads);
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(true, "====> Errore nel monitor: " + e.getMessage());
|
||||
}
|
||||
}, 10L, 30L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static synchronized SelfieProcessor getInstance(int l_numThreads) {
|
||||
if (instance == null) {
|
||||
int threads = (l_numThreads > 0) ? l_numThreads : numThreads;
|
||||
instance = new SelfieProcessor(threads);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void aggiungiInCoda(Selfie selfie) {
|
||||
if (selfie.getFlgStatus() == 0L) {
|
||||
try {
|
||||
selfie.updateFlgStatus(1L);
|
||||
this.queue.put(selfie);
|
||||
DBAdapter.printDebug(true, "Selfie aggiunto alla coda: " + selfie.getId_selfie());
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(true, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(true, "Selfie già elaborato: " + selfie.getId_selfie());
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
try {
|
||||
DBAdapter.printDebug(true, "Arresto di SelfieProcessor...");
|
||||
this.executor.shutdown();
|
||||
if (!this.executor.awaitTermination(10L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(true, "Forzatura della chiusura del pool di thread...");
|
||||
this.executor.shutdownNow();
|
||||
}
|
||||
this.monitor.shutdownNow();
|
||||
instance = null;
|
||||
DBAdapter.printDebug(true, "SelfieProcessor è stato arrestato e l'istanza è stata resettata.");
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(true, "Errore durante lo shutdown: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.face.Selfie;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfieProcessor2 {
|
||||
private static boolean debug = true;
|
||||
|
||||
private static SelfieProcessor2 instance;
|
||||
|
||||
private final BlockingQueue<Selfie> queue;
|
||||
|
||||
private final ExecutorService executor;
|
||||
|
||||
private final ScheduledExecutorService monitor;
|
||||
|
||||
private static int numThreads = 10;
|
||||
|
||||
private SelfieProcessor2(int numThreads) {
|
||||
this.queue = new LinkedBlockingQueue<>();
|
||||
this.executor = Executors.newFixedThreadPool(numThreads);
|
||||
for (int i = 0; i < numThreads; i++)
|
||||
this.executor.submit(new SelfieWorker(this.queue));
|
||||
this.monitor = Executors.newSingleThreadScheduledExecutor();
|
||||
this.monitor.scheduleAtFixedRate(() -> {
|
||||
try {
|
||||
int queueSize = this.queue.size();
|
||||
int activeThreads = ((ThreadPoolExecutor)this.executor).getActiveCount();
|
||||
DBAdapter.printDebug(debug, "Coda attuale: " + queueSize + " | Thread attivi: " + activeThreads + " su " + numThreads);
|
||||
} catch (Exception e) {
|
||||
DBAdapter.printDebug(debug, "Errore nel monitor: " + e.getMessage());
|
||||
}
|
||||
}, 10L, 30L, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
public static synchronized SelfieProcessor2 getInstance(int l_numThreads) {
|
||||
if (instance == null) {
|
||||
int threads = (l_numThreads > 0) ? l_numThreads : numThreads;
|
||||
instance = new SelfieProcessor2(threads);
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void aggiungiInCoda(Selfie selfie) {
|
||||
if (selfie.getFlgStatus() == 0L) {
|
||||
try {
|
||||
selfie.updateFlgStatus(1L);
|
||||
this.queue.put(selfie);
|
||||
DBAdapter.printDebug(debug, "Selfie aggiunto alla coda: " + selfie.getId_selfie());
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(debug, "Errore durante l'aggiunta alla coda: " + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
DBAdapter.printDebug(debug, "Selfie già elaborato: " + selfie.getId_selfie());
|
||||
}
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
try {
|
||||
DBAdapter.printDebug(debug, "Arresto di SelfieProcessor...");
|
||||
this.executor.shutdown();
|
||||
if (!this.executor.awaitTermination(10L, TimeUnit.SECONDS)) {
|
||||
DBAdapter.printDebug(debug, "Forzatura della chiusura del pool di thread...");
|
||||
this.executor.shutdownNow();
|
||||
}
|
||||
this.monitor.shutdownNow();
|
||||
instance = null;
|
||||
DBAdapter.printDebug(debug, "SelfieProcessor è stato arrestato e l'istanza è stata resettata.");
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
DBAdapter.printDebug(debug, "Errore durante lo shutdown: " + e.getMessage());
|
||||
}
|
||||
instance = null;
|
||||
DBAdapter.printDebug(debug, "SelfieProcessor è stato arrestato e l'istanza è stata resettata.");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,194 @@
|
|||
package it.acxent.face.pc;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import it.acxent.common.StatusMsg;
|
||||
import it.acxent.db.DBAdapter;
|
||||
import it.acxent.db.ResParm;
|
||||
import it.acxent.face.Evento;
|
||||
import it.acxent.face.FaceScore;
|
||||
import it.acxent.face.Selfie;
|
||||
import it.acxent.face.callable.ScoringFaceCallableGson;
|
||||
import it.acxent.log.Log;
|
||||
import it.acxent.util.Timer;
|
||||
import it.acxent.util.Vectumerator;
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class SelfieWorker implements Runnable {
|
||||
private final BlockingQueue<Selfie> queue;
|
||||
|
||||
public SelfieWorker(BlockingQueue<Selfie> queue) {
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
public void run() {
|
||||
try {
|
||||
while (true) {
|
||||
Selfie selfie = this.queue.take();
|
||||
System.out.println("Elaborazione iniziata per Selfie: " + selfie.getId_selfie());
|
||||
scoringSelfie(selfie);
|
||||
System.out.println("Elaborazione completata per Selfie: " + selfie.getId_selfie());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
System.err.println("SelfieWorker interrotto: " + e.getMessage());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private ResParm scoringSelfie(Selfie selfie) {
|
||||
Evento evento = selfie.getEvento();
|
||||
String TAG_THREAD_MSG = "SCORING SELFIE " + selfie.getId_selfie();
|
||||
boolean debug = true;
|
||||
StringBuffer errMsg = new StringBuffer();
|
||||
ResParm rp = new ResParm(true);
|
||||
int STEP_STATUS_MSG = 20;
|
||||
Timer timer = new Timer();
|
||||
timer.start();
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, "scoring selfie su worker inizio ");
|
||||
int maxNumberOfThread = selfie.getParm("MAX_NUMBER_OF_THREAD_SCORING_LVL_2").getNumeroInt();
|
||||
int NUM_QUERY_CALLABLE_MAX = selfie.getParm("NUM_QUERY_CALLABLE_LVL_2").getNumeroInt();
|
||||
if (maxNumberOfThread <= 0)
|
||||
maxNumberOfThread = 200;
|
||||
if (NUM_QUERY_CALLABLE_MAX <= 0)
|
||||
NUM_QUERY_CALLABLE_MAX = 95;
|
||||
int NUM_QUERY_CALLABLE = NUM_QUERY_CALLABLE_MAX;
|
||||
final ThreadLocal<Integer> callerTaskCount = ThreadLocal.withInitial(() -> 0);
|
||||
int NUMB_OF_CORES = Runtime.getRuntime().availableProcessors();
|
||||
int corePoolSize = 4;
|
||||
int maxPoolSize = NUMB_OF_CORES * 4;
|
||||
long keepAliveTime = 360L;
|
||||
int blockingQueueSize = maxPoolSize;
|
||||
ThreadPoolExecutor pool = new ThreadPoolExecutor(corePoolSize, maxPoolSize, keepAliveTime, TimeUnit.SECONDS, new LinkedBlockingQueue(blockingQueueSize), new ThreadPoolExecutor.CallerRunsPolicy() {
|
||||
public void rejectedExecution(Runnable r, ThreadPoolExecutor e) {
|
||||
callerTaskCount.set(Integer.valueOf(callerTaskCount.get() + 1));
|
||||
super.rejectedExecution(r, e);
|
||||
}
|
||||
}) {
|
||||
protected void afterExecute(Runnable r, Throwable t) {
|
||||
super.afterExecute(r, t);
|
||||
if (Thread.currentThread() == Thread.currentThread()) {
|
||||
int count = callerTaskCount.get();
|
||||
if (count > 0)
|
||||
callerTaskCount.set(Integer.valueOf(count - 1));
|
||||
}
|
||||
}
|
||||
};
|
||||
Vectumerator<Future<ResParm>> vecF = new Vectumerator();
|
||||
String targetDir = selfie.getParm("PATHFOTO_FACE").getTesto() + selfie.getParm("PATHFOTO_FACE").getTesto();
|
||||
File targetDirFile = new File(targetDir);
|
||||
if (!targetDirFile.exists())
|
||||
targetDirFile.mkdirs();
|
||||
double confDetectLevel = evento.getDetectFaceConfidentThresold();
|
||||
long dysType = selfie.getParm("ZOO_YUNET_SCORING_DYS_TYPE").getNumeroLong();
|
||||
FaceScore fs = new FaceScore(selfie.getApFull());
|
||||
StatusMsg.updateMsgByTag(selfie.getApFull(), TAG_THREAD_MSG, "QUERY TARGET X EVENTO......");
|
||||
Vectumerator<FaceScore> vecFsTarget = fs.findTargetByEvento(evento.getId_evento(), -1L);
|
||||
long i = 0L;
|
||||
JsonObject jsonData = new JsonObject();
|
||||
jsonData.addProperty("dis_type", Long.valueOf(dysType));
|
||||
jsonData.addProperty("conf_threshold", Double.valueOf(confDetectLevel));
|
||||
JsonObject jsonTarget = new JsonObject();
|
||||
jsonTarget.addProperty("id", Long.valueOf(selfie.getId_selfie()));
|
||||
jsonTarget.addProperty("path", selfie.getRealSelfieImgPath());
|
||||
jsonTarget.addProperty("md5", selfie.getMd5());
|
||||
jsonTarget.addProperty("type", "selfie");
|
||||
jsonData.add("target", (JsonElement)jsonTarget);
|
||||
FaceScore currentFs = new FaceScore();
|
||||
String eta = "....";
|
||||
JsonArray jsonQuery = new JsonArray();
|
||||
while (vecFsTarget.hasMoreElements()) {
|
||||
currentFs = (FaceScore)vecFsTarget.nextElement();
|
||||
JsonObject jsonQueryRow = new JsonObject();
|
||||
jsonQueryRow.addProperty("id", Long.valueOf(currentFs.getId_fotoFace()));
|
||||
jsonQueryRow.addProperty("path", currentFs.getFotoFace().getFacePath());
|
||||
jsonQueryRow.addProperty("md5", currentFs.getFotoFace().getMd5());
|
||||
jsonQueryRow.addProperty("type", "face");
|
||||
jsonQuery.add((JsonElement)jsonQueryRow);
|
||||
if (i > 0L && i % (long)NUM_QUERY_CALLABLE == 0L) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, "scoringSelfie: callable sul %. jsonQueryCallable.len " + jsonQuery.size());
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQuery);
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
while (pool.getActiveCount() >= blockingQueueSize)
|
||||
DBAdapter.sleepInSecond(2);
|
||||
jsonQuery = new JsonArray();
|
||||
if (debug) {
|
||||
int activeThreads = pool.getActiveCount();
|
||||
DBAdapter.printDebug(debug, " scoringSelfie: cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + activeThreads + " task in coda: " +
|
||||
|
||||
pool.getQueue().size() + " task sul thread attuale: " +
|
||||
String.valueOf(callerTaskCount.get()) + " len:" + jsonQuery.size() + " numero query callable: " + NUM_QUERY_CALLABLE + " max: " + NUM_QUERY_CALLABLE_MAX);
|
||||
}
|
||||
if (i % (long)STEP_STATUS_MSG == 0L) {
|
||||
int activeThreads = pool.getActiveCount();
|
||||
StatusMsg.updateMsgByTag(selfie.getApFull(), TAG_THREAD_MSG, "cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + activeThreads + " task in coda: " +
|
||||
|
||||
pool.getQueue().size() + " task sul thread attuale: " + String.valueOf(callerTaskCount.get()) + " NUM_QUERY_CALLABLE:" + NUM_QUERY_CALLABLE + "sec. punto foto:" +
|
||||
|
||||
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" +
|
||||
vecFsTarget.getTotNumberOfRecords() + ") ..... ETA: " + eta);
|
||||
}
|
||||
}
|
||||
i++;
|
||||
eta = timer.getEta(i, (long)vecFsTarget.getTotNumberOfRecords());
|
||||
}
|
||||
if (jsonQuery.size() > 0) {
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, "scoringSelfie: callable finale jsonQueryCallable.len " + jsonQuery.size());
|
||||
JsonObject jsonDataCallable = jsonData.deepCopy();
|
||||
jsonDataCallable.add("query", (JsonElement)jsonQuery);
|
||||
ScoringFaceCallableGson ifc = new ScoringFaceCallableGson(evento, jsonDataCallable, targetDir, true);
|
||||
vecF.add(pool.submit(ifc));
|
||||
int activeThreads = pool.getActiveCount();
|
||||
StatusMsg.updateMsgByTag(selfie.getApFull(), TAG_THREAD_MSG, "cores: " + NUMB_OF_CORES + " maxPoolSize:" + maxPoolSize + " current threads number: " + activeThreads + " task in coda: " +
|
||||
|
||||
pool.getQueue().size() + " task sul thread attuale: " + String.valueOf(callerTaskCount.get()) + " NUM_QUERY_CALLABLE:" + NUM_QUERY_CALLABLE + "sec. punto foto:" +
|
||||
|
||||
currentFs.getFoto().getPuntoFoto().getDescrizione() + " (" + i + "/" + vecFsTarget.getTotNumberOfRecords() + ") ..... ETA: " + eta);
|
||||
}
|
||||
StatusMsg.deleteMsgByTag(selfie.getApFull(), TAG_THREAD_MSG);
|
||||
try {
|
||||
for (int fidx = 0; fidx < vecF.getTotNumberOfRecords(); fidx++) {
|
||||
Future<ResParm> currentFuture = (Future<ResParm>)vecF.nextElement();
|
||||
if (currentFuture == null) {
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Errore: Future null per indice " + fidx);
|
||||
} else {
|
||||
rp = currentFuture.get();
|
||||
if (!rp.getStatus()) {
|
||||
errMsg.append(rp.getErrMsg() + "\n");
|
||||
} else {
|
||||
HashSet<FaceScore> hsFs = (HashSet<FaceScore>)rp.getReturnObj();
|
||||
if (hsFs != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
rp.setStatus(false);
|
||||
rp.setMsg("Eccezione vecfuture: " + e.getMessage());
|
||||
}
|
||||
timer.stop();
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " scoringSelfie: FINE!!!: " + timer.getDurata());
|
||||
selfie.updateFlgStatus(99L);
|
||||
if (debug)
|
||||
DBAdapter.printDebug(debug, " scoringSelfie: INVIO COMANDO NOTIFICHE!!!: " + timer.getDurata());
|
||||
Evento.inviaNotificaRemotaWww(selfie.getApFull(), Long.valueOf(selfie.getEvento().getCodiceEventoCliente()).longValue());
|
||||
StatusMsg.deleteMsgByTag(selfie.getApFull(), TAG_THREAD_MSG);
|
||||
Log.addAltro(selfie.getApFull(), "127.0.0.1", 1L, " scoringSelfie: FINE!!! \n" + timer.getDurata() + "\nRisultato: " + rp.getMsg());
|
||||
return rp;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1 @@
|
|||
package it.acxent.face.pc;
|
||||
Loading…
Add table
Add a link
Reference in a new issue