From 646aa5277c1294702e6d0150526d27ffca701bdd Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1s=C3=A1ry=20D=C3=A1niel?= Date: Mon, 26 Nov 2018 15:33:28 +0000 Subject: [PATCH] =?utf8?q?Nexio=20restart=20jav=C3=ADt=C3=A1sa?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C31349 --- .../src/user/commons/nexio/NexioAPI.java | 2 +- .../user/commons/nexio/NexioDataMiner.java | 13 ++- .../user/commons/nexio/NexioDispatcher.java | 86 +++++++++++-------- 3 files changed, 58 insertions(+), 43 deletions(-) diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java index ba4306d0..fd2d114e 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioAPI.java @@ -33,7 +33,7 @@ public class NexioAPI implements INexioAPI { DB db; try { db = NoSQLUtils.getNoSQLDB(); - DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); DBCursor find = collection.find().sort(new BasicDBObject(MODIFIEDTIMESTAMP, new BasicDBList(-1, "$date"))); if (find.hasNext()) result = find.toArray(); diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDataMiner.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDataMiner.java index 00462776..cd17ff8e 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDataMiner.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDataMiner.java @@ -43,7 +43,6 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { private static final String RECORDDATE = "recorddate"; private static final String LONGNAMEID = "longnameid"; private static final String ID = "id"; - public static final String CLIP_COLLECTION_NAME = "nexioclips"; private static final String VIDEOBITRATE = "videobitrate"; private static final String VIDEOFORMAT = "videoformat"; private static final String KILLDATE = "killdate"; @@ -80,7 +79,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { } private void ensureIndexes() { - DBCollection collection = db.getCollection(CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); if (collection.count() == 0) collection.ensureIndex(LONGNAMEID); } @@ -163,7 +162,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { private Map readClips() { Map result = new HashMap<>(); - DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); DBCursor find = collection.find(); if (find.hasNext()) { List clips = ListUtils.cast(find.toArray()); @@ -181,7 +180,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { if (localNames.isEmpty()) logger.debug("Nothing to remove"); - DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); for (String name : localNames) { logger.debug("Removing {}", name); @@ -196,7 +195,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { } public void reset() { - db.getCollection(CLIP_COLLECTION_NAME).drop(); + db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME).drop(); } @Override @@ -236,7 +235,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { private void storeClip(BasicDBObject clip, Map localClips) { logger.trace("Enter"); - DBCollection collection = db.getCollection(CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); String name = clip.getString(LONGNAMEID); BasicDBObject localClip = localClips.get(name); if (localClip == null) { @@ -271,7 +270,7 @@ public class NexioDataMiner implements Runnable, INexioChangeListener { public void transferClips() { try (Connection con = getSQLConnection()) { - DBCollection collection = db.getCollection(CLIP_COLLECTION_NAME); + DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME); collection.drop(); transferClips(con, collection); } catch (Exception e) { diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDispatcher.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDispatcher.java index 51097f8b..165c585b 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDispatcher.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDispatcher.java @@ -1,8 +1,6 @@ package user.commons.nexio; import java.util.Iterator; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -39,17 +37,15 @@ public class NexioDispatcher implements ClipEventListener { private static final String ID = "id"; private static final String VIDEO_FORMAT = "videoformat"; private static final String VIDEO_BITRATE = "videobitrate"; - private static final String FILESIZE = "filesize"; private static final String KILLDATE = "killdate"; private static final String DURATION = "duration"; private static final String MODIFIEDTIMESTAMP = "modifiedtimestamp"; private static final String EXTAGENCY = "extagency"; private static final String RECORDDATE = "recorddate"; private static final String LONGNAMEID = "longnameid"; - public static final String CLIP_COLLECTION_NAME = "nexioclips"; + public static final String CLIP_COLLECTION_NAME = System.getProperty("jobengine.nexio.name"); static private final byte[] GET_SPECIAL_ID_ATTRIBUTES_REQ = { (byte) 0xC8, (byte) 0x84 }; static private final char[] hexArray = "0123456789ABCDEF".toCharArray(); - private static final ExecutorService executor = Executors.newFixedThreadPool(1); public static String bytesToBin(byte[] bytes) { StringBuilder result = new StringBuilder(); @@ -84,6 +80,8 @@ public class NexioDispatcher implements ClipEventListener { return str; } + private boolean restartInProgress; + private INexioChangeListener nexioChangeListener; private DB db; @@ -217,7 +215,8 @@ public class NexioDispatcher implements ClipEventListener { logger.debug("Found NEXIO clip: {} XID IS MISSING!!", clip.getId()); } } catch (Exception e) { - logger.catching(e); + logger.error(e.getMessage()); + //logger.catching(e); } } logger.info("NEXIO metadata import completed."); @@ -249,7 +248,9 @@ public class NexioDispatcher implements ClipEventListener { logger.info("Initial clip import completed"); Mediabase mediabase = NexioDispatcher.this.controller.getMediabase(); mediaListener = mediabase.createMediaListener(disabled, NexioDispatcher.this); + setRestartInProgress(false); mediaListener.startListener(); + } catch (Exception e) { logger.catching(e); } @@ -257,6 +258,10 @@ public class NexioDispatcher implements ClipEventListener { worker.start(); } + synchronized public boolean isRestartInProgress() { + return restartInProgress; + } + /* Nem foglalkozunk a clippel ha: C8 84 Get Special ID Attributes @@ -291,14 +296,14 @@ public class NexioDispatcher implements ClipEventListener { } /* - + int c = connection.read(buffer, 0, 2); //2 bytes hosszan az idokozben hozzaadott id-k szamossaga if (c < 2) { throw new ProtocolException("c, 2, 2"); } //MSB, LSB - + return nofIds; */ return ret; @@ -331,8 +336,8 @@ public class NexioDispatcher implements ClipEventListener { @Override public void restart() { + logger.info("Restart (already in progress {})", restartInProgress); shutdown(); - startup(); } private void saveClipIntoMongo(BasicDBObject clip) { @@ -369,38 +374,49 @@ public class NexioDispatcher implements ClipEventListener { this.nexioChangeListener = nexioChangeListener; } + synchronized public void setRestartInProgress(boolean restartInProgress) { + this.restartInProgress = restartInProgress; + logger.info("Restart in progress {}", isRestartInProgress()); + } + public void shutdown() { - if (!disabled) { - if (mediaListener != null) { - mediaListener.disconnect(); - mediaListener = null; - } - if (controller != null) { - controller.disconnect(); - controller = null; - } - try { - worker.join(); - } catch (InterruptedException e) { - logger.catching(e); - } + if (disabled) + return; + if (isRestartInProgress()) { + return; + } + + logger.info("Shutting down Nexio service"); + setRestartInProgress(true); + if (mediaListener != null) { + mediaListener.disconnect(); + mediaListener = null; + } + if (controller != null) { + controller.disconnect(); + controller = null; } } public void startup() { - if (!disabled) { - this.controller = new Controller(NEXIO_HOST); - try { - this.controller.connect(); - } catch (Exception e) { - logger.catching(e); - return; - } - dropAllClipsFromMongo(); - ensureIndexes(); - innerStartup(); - } else + if (disabled) { logger.info("Nexio service is disabled"); + return; + } + + logger.info("Starting up Nexio service"); + setRestartInProgress(true); + this.controller = new Controller(NEXIO_HOST); + try { + this.controller.connect(); + } catch (Exception e) { + logger.catching(e); + return; + } + dropAllClipsFromMongo(); + ensureIndexes(); + innerStartup(); + } } -- 2.54.0