From: Rendek RĂ³bert Date: Fri, 13 Oct 2017 15:01:16 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=731913cd7bdecc577557728a1fcfb9b6cc097ee1;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C30618 --- diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java index 262d6bba..62d090f5 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioClipEventDispatcher.java @@ -98,7 +98,7 @@ public class NexioClipEventDispatcher implements ClipEventListener { //nexio init this.controller = new Controller(NEXIO_HOST); this.controller.connect(); - this.controller.getMediabase().getMediaListener().addClipEventListener(this); + //this.controller.getMediabase().getMediaListener().addClipEventListener(this); logger.info("NexioClipEventDispatcher nexio server is connected."); this.progressListenerList = new EventListenerList(); @@ -109,18 +109,21 @@ public class NexioClipEventDispatcher implements ClipEventListener { //load clips into mongo Thread importThread = new Thread(new Runnable() { - @Override public void run() { try { + //1. kezdeti masolas copyClipsIntoMongo(); + //2. esemeny feliratkozas + NexioClipEventDispatcher.this.controller.getMediabase().startMediaListener(); + NexioClipEventDispatcher.this.controller.getMediabase().getMediaListener().addClipEventListener(NexioClipEventDispatcher.this); } catch (Exception e) { logger.catching(e); } } }); - importThread.start(); + } catch (Exception exc) { logger.error("", exc); @@ -138,9 +141,19 @@ public class NexioClipEventDispatcher implements ClipEventListener { if (evt.getEventType() == ClipEventType.CLIP_ADDED) { // if (isValidClip(evt.getClip())) { BasicDBObject jsClip = convertClipToJSON(evt.getClip()); - //cache??? - Map mongoClips = loadClipsFromMongo(); - saveClipIntoMongo(jsClip, mongoClips); + + String fileName = jsClip.getString(LONGNAMEID); + if(fileName != null && !"".equals(fileName)){ + logger.debug("clipEventPerformed clip: {} {}", evt.getClip().getId(), fileName); + //cache??? + + HashMap clipsForId = new HashMap(); + Map clipsForXID = loadClipsFromMongo(clipsForId); + saveClipIntoMongo(jsClip, clipsForXID, clipsForId); + }else{ + logger.debug("clipEventPerformed clip: {}", evt.getClip() == null ? "null" : evt.getClip().getId()); + } + // } } else if (evt.getEventType() == ClipEventType.CLIP_DELETED) { BasicDBObject jsClip = new BasicDBObject(); @@ -239,10 +252,20 @@ public class NexioClipEventDispatcher implements ClipEventListener { Map emptyMap = new HashMap(); Iterator clips = controller.getMediabase().getClips(); while (clips.hasNext()) { - Clip clip = clips.next(); - BasicDBObject jsonClip = convertClipToJSON(clip); - logger.debug("Found NEXIO clip: {} {}", clip.getId(), clip.getXid()); - this.saveClipIntoMongo(jsonClip, emptyMap); + Clip clip = null; + try{ + clip = clips.next(); + BasicDBObject jsonClip = convertClipToJSON(clip); + String fileName = jsonClip.getString(LONGNAMEID); + if(fileName != null && !"".equals(fileName)){ + logger.debug("Found NEXIO clip: {} {}", clip.getId(), fileName); //clip.getXid() hibat dob + this.saveClipIntoMongo(jsonClip, emptyMap, emptyMap); + }else{ + logger.debug("Found NEXIO clip: {} XID IS MISSING!!", clip.getId()); + } + }catch(Exception e){ + logger.error("", e); + } } logger.info("NEXIO metadata import completed."); } @@ -305,15 +328,19 @@ public class NexioClipEventDispatcher implements ClipEventListener { return ret; } - private Map loadClipsFromMongo() { + private Map loadClipsFromMongo(Map clipsForId) { Map result = new HashMap<>(); DBCollection collection = db.getCollection(NexioClipEventDispatcher.CLIP_COLLECTION_NAME); DBCursor find = collection.find(); if (find.hasNext()) { List clips = ListUtils.cast(find.toArray()); result = ListUtils.map(clips, item -> item.getString(LONGNAMEID)); - for (BasicDBObject clip : clips) + for (BasicDBObject clip : clips){ result.put(clip.getString(LONGNAMEID), clip); + if(clipsForId != null){ + clipsForId.put(clip.getString(ID), clip); + } + } } return result; } @@ -363,18 +390,25 @@ public class NexioClipEventDispatcher implements ClipEventListener { } */ - private void saveClipIntoMongo(BasicDBObject clip, Map localClips) { + private void saveClipIntoMongo(BasicDBObject clip, Map clipsForXID, Map clipsForID) { DBCollection collection = db.getCollection(CLIP_COLLECTION_NAME); - String name = clip.getString(LONGNAMEID); - BasicDBObject localClip = localClips.get(name); - if (localClip == null) { + String xid = clip.getString(LONGNAMEID); + String id = clip.getString(ID); + + BasicDBObject clipForXID = clipsForXID.get(xid); + BasicDBObject clipForID = clipsForID.get(id); + + //rename-nel a clipForXID null lesz de a clipForID nem ezert nem kell create + if (clipForXID == null && clipForID == null) { collection.save(clip); onCreate(clip); } else { - clip.put("_id", localClip.get("_id")); - if (!clip.equals(localClip)) { - collection.save(clip); - onUpdate(clip); + if(clipForID != null){ + clip.put("_id", clipForID.get("_id")); + if (!clip.equals(clipForID)) { + collection.save(clip); + onUpdate(clip); + } } } } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Mediabase.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Mediabase.java index d16c3bbd..a5f8a6e7 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Mediabase.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Mediabase.java @@ -14,5 +14,8 @@ public interface Mediabase { public MediaListener getMediaListener(); + public void startMediaListener(); + public NexioServerProtocol getProtocol(); + } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediabaseImpl.java b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediabaseImpl.java index 67a36a4a..801e12a7 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediabaseImpl.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediabaseImpl.java @@ -16,9 +16,21 @@ class MediabaseImpl implements Mediabase { //KONSTRUKTOR public MediabaseImpl(NexioServerProtocol protocol) { this.protocol = protocol; - this.mediaListener = new MediaListener(this, protocol.getConnection().getHost(), protocol.getConnection().getPort()); } + public MediabaseImpl(NexioServerProtocol protocol, boolean startMediaListener) { + this.protocol = protocol; + if(startMediaListener){ + this.mediaListener = new MediaListener(this, protocol.getConnection().getHost(), protocol.getConnection().getPort()); + } + } + + public void startMediaListener(){ + if(this.mediaListener == null){ + this.mediaListener = new MediaListener(this, protocol.getConnection().getHost(), protocol.getConnection().getPort()); + } + } + @Override public Clip getClip(Id id) throws IOException, ProtocolException { if (id == null) {