Skip to content
This repository has been archived by the owner on May 23, 2019. It is now read-only.

Commit

Permalink
Update #250 and refactor Instance Status/Action, correct AppManager n…
Browse files Browse the repository at this point in the history
…ame.
  • Loading branch information
hdsdi3g committed Apr 14, 2017
1 parent beb850b commit 1169263
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 68 deletions.
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/bcastautomation/BCAWatcher.java
Expand Up @@ -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();
Expand Down
3 changes: 1 addition & 2 deletions app/hd3gtv/mydmam/ftpserver/FTPGroup.java
Expand Up @@ -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);
}
}

Expand Down
37 changes: 21 additions & 16 deletions app/hd3gtv/mydmam/manager/AppManager.java
Expand Up @@ -51,8 +51,12 @@ public final class AppManager implements InstanceActionReceiver, InstanceStatusI
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);
Expand All @@ -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");
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions app/hd3gtv/mydmam/manager/InstanceActionReceiver.java
Expand Up @@ -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;

}
10 changes: 2 additions & 8 deletions app/hd3gtv/mydmam/manager/InstanceStatus.java
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();
}
Expand Down
23 changes: 23 additions & 0 deletions app/hd3gtv/mydmam/manager/InstanceStatusAction.java
@@ -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();

}
4 changes: 1 addition & 3 deletions app/hd3gtv/mydmam/manager/InstanceStatusItem.java
Expand Up @@ -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();

}
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/manager/JobCreator.java
Expand Up @@ -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);
}

/**
Expand Down
3 changes: 1 addition & 2 deletions app/hd3gtv/mydmam/manager/ServiceNG.java
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/manager/WorkerExporter.java
Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/transcode/ProcessingKitEngine.java
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion app/hd3gtv/mydmam/transcode/TranscoderWorker.java
Expand Up @@ -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));
}

}
Expand Down
16 changes: 13 additions & 3 deletions app/hd3gtv/mydmam/transcode/watchfolder/WatchFolderEntry.java
Expand Up @@ -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() {
Expand Down Expand Up @@ -882,7 +882,7 @@ public JsonElement getInstanceStatusItem() {
}

public String getReferenceKey() {
return name;
return manager.getReferenceKey() + ":" + name;
}

public Class<?> getInstanceStatusItemReferenceClass() {
Expand All @@ -894,8 +894,18 @@ public Class<? extends InstanceActionReceiver> getClassToCallback() {
}

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);
}
}
}

Expand Down
34 changes: 14 additions & 20 deletions app/react/mydmam/async/manager/modules.jsx
Expand Up @@ -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}
Expand Down
8 changes: 4 additions & 4 deletions conf/messages-db.json
Expand Up @@ -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
}
]
}
1 change: 0 additions & 1 deletion conf/messages.en
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion conf/messages.fr
Expand Up @@ -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
Expand Down
Binary file modified public/javascripts/_reduced/_internal_concated.js.gz
Binary file not shown.
Binary file modified public/javascripts/i18n/en.js.gz
Binary file not shown.
Binary file modified public/javascripts/i18n/fr.js.gz
Binary file not shown.

0 comments on commit 1169263

Please sign in to comment.