Permalink
Browse files

Update #250 and refactor Instance Status/Action, correct AppManager n…

…ame.
  • Loading branch information...
hdsdi3g committed Apr 14, 2017
1 parent beb850b commit 11692634b51c8d5b37cdbf9580b05c9eb902f969
@@ -84,7 +84,7 @@ public BCAWatcher(AppManager manager) throws ReflectiveOperationException, IOExc
}
Loggers.BroadcastAutomation.info("Init engine watcher: " + getInstanceStatusItem().toString());
manager.getInstanceStatus().registerInstanceStatusItem(this);
manager.registerInstanceStatusAction(this);
watch = new BCAWatcherThread(this);
watch.start();
@@ -107,8 +107,7 @@ public static boolean isConfigured() {
public static void registerAppManager(AppManager manager) {
for (FTPGroup group : declared_groups.values()) {
manager.registerInstanceActionReceiver(group);
manager.getInstanceStatus().registerInstanceStatusItem(group);
manager.registerInstanceStatusAction(group);
}
}
@@ -51,8 +51,12 @@
private String app_name;
private ArrayList<InstanceActionReceiver> all_instance_action_receviers;
public AppManager() {
this.app_name = "Manager";
public AppManager(String app_name) {
this.app_name = app_name;
if (app_name == null) {
throw new NullPointerException("\"app_name\" can't to be null");
}
all_instance_action_receviers = new ArrayList<InstanceActionReceiver>();
all_instance_action_receviers.add(this);
service_exception = new ServiceException(this);
@@ -69,13 +73,6 @@ String getAppName() {
return app_name;
}
void setAppName(String app_name) {
this.app_name = app_name;
if (app_name == null) {
throw new NullPointerException("\"app_name\" can't to be null");
}
}
public void register(WorkerNG worker) {
if (worker == null) {
throw new NullPointerException("\"worker\" can't to be null");
@@ -112,17 +109,25 @@ public void register(TriggerJobCreator trigger_creator) {
all_instance_action_receviers.add(trigger_creator);
}
public void registerInstanceActionReceiver(InstanceActionReceiver recevier) {
if (recevier == null) {
public void registerInstanceStatusAction(InstanceStatusAction instance) {
if (instance == null) {
throw new NullPointerException("\"recevier\" can't to be null");
}
if (recevier.getClassToCallback() == null) {
throw new NullPointerException("recevier callback class can't to be null");
if (instance.getReferenceKey() == null) {
throw new NullPointerException("instance ReferenceKey can't to be null");
}
if (recevier.getReferenceKey() == null) {
throw new NullPointerException("recevier ReferenceKey can't to be null");
if (instance instanceof InstanceActionReceiver) {
InstanceActionReceiver recevier = (InstanceActionReceiver) instance;
if (recevier.getClassToCallback() == null) {
throw new NullPointerException("recevier callback class can't to be null");
}
all_instance_action_receviers.add(recevier);
}
if (instance instanceof InstanceStatusItem) {
instance_status.addItem((InstanceStatusItem) instance);
}
all_instance_action_receviers.add(recevier);
}
/*public static void unRegisterRecevier(InstanceActionReceiver recevier) {
@@ -18,15 +18,13 @@
import com.google.gson.JsonObject;
public interface InstanceActionReceiver {
public interface InstanceActionReceiver extends InstanceStatusAction {
/**
* Beware: use class.getSimpleName() to comparate. If 2 differents class has the same name, an error will be thrown.
*/
public Class<? extends InstanceActionReceiver> getClassToCallback();
public String getReferenceKey();
public void doAnAction(JsonObject order) throws Exception;
}
@@ -301,13 +301,7 @@ private ThreadStackTrace importThread(Thread t, StackTraceElement[] stes) {
}
}
public void registerInstanceStatusItem(InstanceStatusItem item) {
if (item == null) {
throw new NullPointerException("\"item\" can't to be null");
}
if (item.getReferenceKey() == null) {
throw new NullPointerException("\"instance status item name\" can't to be null");
}
void addItem(InstanceStatusItem item) {
items.add(item);
}
@@ -481,7 +475,7 @@ public void onFoundRow(Row<String, String> row) throws Exception {
*/
public static InstanceStatus getStatic() {
if (static_manager == null) {
static_manager = new AppManager();
static_manager = new AppManager("(Not loaded)");
}
return static_manager.getInstanceStatus();
}
@@ -0,0 +1,23 @@
/*
* This file is part of MyDMAM.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* Copyright (C) hdsdi3g for hd3g.tv 2017
*
*/
package hd3gtv.mydmam.manager;
public interface InstanceStatusAction {
public String getReferenceKey();
}
@@ -18,12 +18,10 @@
import com.google.gson.JsonElement;
public interface InstanceStatusItem {
public interface InstanceStatusItem extends InstanceStatusAction {
public JsonElement getInstanceStatusItem();
public String getReferenceKey();
public Class<?> getInstanceStatusItemReferenceClass();
}
@@ -94,7 +94,7 @@ public JobCreator(AppManager manager) {
declarations = new ArrayList<Declaration>(1);
reference_key = getClass().getName().toLowerCase() + ":" + UUID.randomUUID().toString();
manager.getInstanceStatus().registerInstanceStatusItem(this);
manager.registerInstanceStatusAction(this);
}
/**
@@ -91,8 +91,7 @@ public ServiceNG(boolean enable_play, boolean enable_ftpserver, boolean enable_b
names.add("Background services");
}
manager = new AppManager();
manager.setAppName(names.toString());
manager = new AppManager(names.toString());
WatchdogLogConf watch_log_conf = new WatchdogLogConf();
watch_log_conf.start();
@@ -112,7 +112,7 @@ private WorkerExporter() {
worker_class = worker.getClass().getName();
reference_key = worker.getReferenceKey();
update();
manager.getInstanceStatus().registerInstanceStatusItem(this);
manager.registerInstanceStatusAction(this);
}
public String getCurrent_job_key() {
@@ -58,7 +58,7 @@ public ProcessingKit get(String class_name) {
Loggers.Transcode.info("Load Processingkit " + pkit);
if (manager != null) {
manager.getInstanceStatus().registerInstanceStatusItem(pkit);
manager.registerInstanceStatusAction(pkit);
}
return pkit;
@@ -130,7 +130,7 @@ public static void declareTranscoders(AppManager manager) throws NullPointerExce
List<TranscodeProfile> transcode_profiles = TranscodeProfile.getAllTranscodeProfiles();
for (int pos = 0; pos < transcode_profiles.size(); pos++) {
manager.getInstanceStatus().registerInstanceStatusItem(transcode_profiles.get(pos));
manager.registerInstanceStatusAction(transcode_profiles.get(pos));
}
}
@@ -287,7 +287,7 @@ private void addToCopySourceFileList(ArrayList<String> send_source_to_dest, Arra
Loggers.Transcode_WatchFolder.info("Load watchfolder entry " + log);
}
manager.getInstanceStatus().registerInstanceStatusItem(this);
manager.registerInstanceStatusAction(this);
}
synchronized void stopWatchfolderScans() {
@@ -882,7 +882,7 @@ public JsonElement getInstanceStatusItem() {
}
public String getReferenceKey() {
return name;
return manager.getReferenceKey() + ":" + name;
}
public Class<?> getInstanceStatusItemReferenceClass() {
@@ -894,8 +894,18 @@ public String getReferenceKey() {
}
public void doAnAction(JsonObject order) throws Exception {
if (isAlive() == false) {
return;
}
if (order.has("paused")) {
paused = order.get("paused").getAsString().equals("true");
paused = order.get("paused").getAsBoolean();
if (paused) {
Loggers.Transcode_WatchFolder.info("Pause watch for " + name + " to " + source_storage);
} else {
Loggers.Transcode_WatchFolder.info("Switch off pause for " + name + " to " + source_storage);
}
}
}
@@ -280,31 +280,25 @@ mydmam.module.register("WatchFolderEntry", {
</p>);
}
var on_toogle_enable_disable = function(ref){
console.log(ref);//TODO
var on_toogle_enable_disable = function(want_to_paused){
manager.createInstanceAction("WatchFolderEntry", item.key, {paused: want_to_paused == "true"});
};
var btn_label_paused = (<mydmam.async.BtnEnableDisable
simplelabel={!manager.canCreateInstanceAction()}
enabled={true}
/* enabled={content.paused == false}*/
labelenabled={i18n("manager.items.watchfolderentry.paused")}
labeldisabled={i18n("manager.items.watchfolderentry.notpaused")}
onEnable={on_toogle_enable_disable}
onDisable={on_toogle_enable_disable}
/*reference={content.paused ? "false" : "true"} />);*/
reference={"false"} />);
var btn_label_alive = (<mydmam.async.BtnEnableDisable
simplelabel={true}
enabled={content.isalive}
labelenabled={i18n("manager.items.watchfolderentry.enabled")}
labeldisabled={i18n("manager.items.watchfolderentry.disabled")}
reference={content.isalive ? "disable" : "enable"} />);
var btn_label_paused = i18n("manager.items.watchfolderentry.disabled");
if (content.isalive) {
btn_label_paused = (<mydmam.async.BtnEnableDisable
simplelabel={!manager.canCreateInstanceAction()}
enabled={!content.paused}
labelenabled={i18n("manager.items.watchfolderentry.notpaused")}
labeldisabled={i18n("manager.items.watchfolderentry.paused")}
onEnable={on_toogle_enable_disable}
onDisable={on_toogle_enable_disable}
reference={content.paused ? "false" : "true"} />);
}
return (<div>
<p>
{btn_label_alive} {btn_label_paused}
{btn_label_paused}
</p>
{i18n("manager.items.watchfolderentry.source")} <span className="badge badge-warning">{content.source_storage}</span>
{want_to_stop}
View
@@ -2,13 +2,13 @@
"entries": [
{
"lang": "en",
"hash": "bd5c4a52d043f27ea35fdd1ee0acf6d2",
"size": 508
"hash": "e1b44f8190acefeca105ad7e0ca766d0",
"size": 509
},
{
"lang": "fr",
"hash": "a53de9879f0460c6b90b039e11c8fa2f",
"size": 508
"hash": "96243d212c311c2b38831f9988ac51ff",
"size": 509
}
]
}
View
@@ -126,7 +126,6 @@ manager.items.watchfolderentry.min_file_size=Minimum file size:
manager.items.watchfolderentry.time_to_sleep_between_scans=Time between two scans: %s sec
manager.items.watchfolderentry.time_to_wait_growing_file=Time to wait after the file size has done to stop growing: %s sec
manager.items.watchfolderentry.want_to_stop=Watchfolder is waiting to stop...
manager.items.watchfolderentry.enabled=Enabled
manager.items.watchfolderentry.disabled=Disabled
manager.items.watchfolderentry.paused=Paused
manager.items.watchfolderentry.notpaused=Not paused
View
@@ -126,7 +126,6 @@ manager.items.watchfolderentry.min_file_size=Taille minimum du fichier :
manager.items.watchfolderentry.time_to_sleep_between_scans=Temps entre deux scans : %s sec
manager.items.watchfolderentry.time_to_wait_growing_file=Temps à attendre après que le la taille du fichier ai fini de se cesser de croître : %s sec
manager.items.watchfolderentry.want_to_stop=Le watchfolder est en cours d'arrêt...
manager.items.watchfolderentry.enabled=Activé
manager.items.watchfolderentry.disabled=Desactivé
manager.items.watchfolderentry.paused=En pause
manager.items.watchfolderentry.notpaused=En fonction
View
Binary file not shown.
View
BIN -131 Bytes (98%) public/javascripts/i18n/en.js.gz
Binary file not shown.
View
BIN -46 Bytes (99%) public/javascripts/i18n/fr.js.gz
Binary file not shown.

0 comments on commit 1169263

Please sign in to comment.