git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorVásáry Dániel <daniel.vasary@userrendszerhaz.hu>
Tue, 17 Apr 2018 14:44:15 +0000 (14:44 +0000)
committerVásáry Dániel <daniel.vasary@userrendszerhaz.hu>
Tue, 17 Apr 2018 14:44:15 +0000 (14:44 +0000)
15 files changed:
server/user.jobengine.osgi.commons/META-INF/MANIFEST.MF
server/user.jobengine.osgi.commons/src/user/commons/nexio/NexioDispatcher.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/ClipEventListener.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Controller.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediaListener.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/Mediabase.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/MediabaseImpl.java
server/user.jobengine.osgi.commons/src/user/commons/nexio/api/samples/ListMetabaseContents.java
server/user.jobengine.osgi.server/pages/joblist.zul
server/user.jobengine.osgi.server/pages/searchitems.zul
server/user.jobengine.osgi.server/resources/i3-label_hu.properties
server/user.jobengine.osgi.server/src/user/jobengine/zk/model/JobListModel.java
server/user.jobengine.osgi.server/src/user/jobengine/zk/model/SearchModel.java
server/user.jobengine.osgi.services/META-INF/MANIFEST.MF
server/user.jobengine.osgi.services/src/user/jobengine/osgi/ws/nexio/NexioWSServlet.java

index 51f1af6fc6c781783cef70c45da2c359e3f93d2a..cd541195e88a0e03cc6b1d693cc1577aac96a9b7 100644 (file)
@@ -23,6 +23,7 @@ Export-Package: user.commons,
  user.commons.logging,
  user.commons.morpheus,
  user.commons.nexio,
+ user.commons.nexio.api,
  user.commons.nosql,
  user.commons.octopus,
  user.commons.rcc,
index b17a4b695976e1fa36bd5ba8dfa566f74db4dc7d..4fffa70e580f323fe9e052687d2bfd9d5f44b260 100644 (file)
@@ -1,33 +1,26 @@
 package user.commons.nexio;\r
 \r
-import java.io.UnsupportedEncodingException;\r
-import java.util.HashMap;\r
 import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Map;\r
 import java.util.concurrent.ExecutorService;\r
 import java.util.concurrent.Executors;\r
 \r
-import javax.swing.event.EventListenerList;\r
-\r
 import org.apache.logging.log4j.LogManager;\r
 import org.apache.logging.log4j.Logger;\r
 \r
 import com.ibm.nosql.json.api.BasicDBObject;\r
 import com.ibm.nosql.json.api.DB;\r
 import com.ibm.nosql.json.api.DBCollection;\r
-import com.ibm.nosql.json.api.DBCursor;\r
 \r
-import user.commons.ListUtils;\r
 import user.commons.nexio.api.Clip;\r
 import user.commons.nexio.api.ClipEvent;\r
 import user.commons.nexio.api.ClipEventListener;\r
 import user.commons.nexio.api.ClipEventType;\r
 import user.commons.nexio.api.Controller;\r
+import user.commons.nexio.api.MediaListener;\r
+import user.commons.nexio.api.Mediabase;\r
 import user.commons.nexio.server.protocol.Connection;\r
 import user.commons.nexio.server.protocol.GetExtendedFieldCommand;\r
 import user.commons.nosql.NoSQLUtils;\r
-import user.commons.remotestore.IProgressEventListener;\r
 \r
 /**\r
  * NexioWSServlet hozza letre. Indulaskor betolti a teljes nexio clip listat mongodb-be. Beregisztralja magat ClipEventListener-nek. Az erkezo esemenyekkel\r
@@ -91,52 +84,50 @@ public class NexioDispatcher implements ClipEventListener {
                return str;\r
        }\r
 \r
-       private EventListenerList progressListenerList;\r
        private INexioChangeListener nexioChangeListener;\r
        private DB db;\r
 \r
        private String NEXIO_HOST = System.getProperty("nexio.host");\r
        private Controller controller = null;\r
 \r
+       private boolean disabled;\r
+\r
+       private Thread worker;\r
+\r
+       private MediaListener mediaListener;\r
+\r
        public NexioDispatcher() {\r
                this.db = NoSQLUtils.getNoSQLDB();\r
-       }\r
-\r
-       public void addProgressListener(IProgressEventListener listener) {\r
-               progressListenerList.add(IProgressEventListener.class, listener);\r
+               disabled = Boolean.parseBoolean(System.getProperty(NEXIO_DISABLE, "false"));\r
        }\r
 \r
        @Override\r
        public void clipEventPerformed(ClipEvent evt) {\r
+               //logger.info("ClipEvent {} {}", evt.getEventType(), evt.getClip());\r
+               if (disabled)\r
+                       return;\r
                try {\r
-                       //DELETE-nel csak az id van kitoltve a CLIP-en, ezert exception jon!!!\r
                        if (evt.getEventType() == ClipEventType.CLIP_ADDED) {\r
-                               //                              if (isValidClip(evt.getClip())) {\r
                                BasicDBObject jsClip = clipToJSON(evt.getClip());\r
 \r
                                String fileName = jsClip.getString(LONGNAMEID);\r
                                if (fileName != null && !"".equals(fileName)) {\r
-                                       logger.debug("clipEventPerformed clip: {} {}", evt.getClip().getId(), fileName);\r
-                                       //cache???\r
-\r
-                                       //                                      HashMap<String, BasicDBObject> clipsForId = new HashMap<String, BasicDBObject>();\r
-                                       //                                      Map<String, BasicDBObject> clipsForXID = loadClipsFromMongo(clipsForId);\r
                                        saveClipIntoMongo(jsClip);\r
                                } else {\r
-                                       logger.debug("clipEventPerformed clip: {}", evt.getClip() == null ? "null" : evt.getClip().getId());\r
+                                       logger.warn("LONGNAMEID is empty! ", evt.getClip().getId());\r
                                }\r
 \r
-                               //                              }\r
                        } else if (evt.getEventType() == ClipEventType.CLIP_DELETED) {\r
                                BasicDBObject jsClip = new BasicDBObject();\r
-                               jsClip.put(ID, evt.getClip().getId().get()); //Unique internal ID\r
+                               jsClip.put(ID, evt.getClip().getId().get());\r
                                removeDeleted(jsClip);\r
                        } else if (evt.getEventType() == ClipEventType.LISTENER_RESTART_NEEDED) {\r
                                shutdown();\r
                                startup();\r
+                               logger.info("Nexio dispatcher restarted");\r
                        }\r
-               } catch (Exception exc) {\r
-                       logger.error("", exc);\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
                }\r
        }\r
 \r
@@ -288,36 +279,19 @@ public class NexioDispatcher implements ClipEventListener {
                }\r
 \r
                /*\r
-\r
+               \r
                                int c = connection.read(buffer, 0, 2);\r
                                //2 bytes hosszan az idokozben hozzaadott id-k szamossaga\r
                                if (c < 2) {\r
                                        throw new ProtocolException("c, 2, 2");\r
                                }\r
                                //MSB, LSB\r
-\r
+               \r
                                return nofIds;\r
                        */\r
                return ret;\r
        }\r
 \r
-       private Map<String, BasicDBObject> loadClipsFromMongo(Map<String, BasicDBObject> clipsForId) {\r
-               Map<String, BasicDBObject> result = new HashMap<>();\r
-               DBCollection collection = db.getCollection(NexioDispatcher.CLIP_COLLECTION_NAME);\r
-               DBCursor find = collection.find();\r
-               if (find.hasNext()) {\r
-                       List<BasicDBObject> clips = ListUtils.cast(find.toArray());\r
-                       result = ListUtils.map(clips, item -> item.getString(LONGNAMEID));\r
-                       for (BasicDBObject clip : clips) {\r
-                               result.put(clip.getString(LONGNAMEID), clip);\r
-                               if (clipsForId != null) {\r
-                                       clipsForId.put(clip.getString(ID), clip);\r
-                               }\r
-                       }\r
-               }\r
-               return result;\r
-       }\r
-\r
        //dispatch events to NexioWSServlet\r
        public void onCreate(BasicDBObject data) {\r
                logger.debug("onCreate clip: " + data);\r
@@ -343,8 +317,10 @@ public class NexioDispatcher implements ClipEventListener {
                onDelete(clipToDelete);\r
        }\r
 \r
-       public void removeProgressListener(IProgressEventListener listener) {\r
-               progressListenerList.remove(IProgressEventListener.class, listener);\r
+       @Override\r
+       public void restart() {\r
+               shutdown();\r
+               startup();\r
        }\r
 \r
        private void saveClipIntoMongo(BasicDBObject clip) {\r
@@ -382,7 +358,19 @@ public class NexioDispatcher implements ClipEventListener {
        }\r
 \r
        public void shutdown() {\r
-               executor.shutdownNow();\r
+               if (mediaListener != null) {\r
+                       mediaListener.disconnect();\r
+                       mediaListener = null;\r
+               }\r
+               if (controller != null) {\r
+                       controller.disconnect();\r
+                       controller = null;\r
+               }\r
+               try {\r
+                       worker.join();\r
+               } catch (InterruptedException e) {\r
+                       logger.catching(e);\r
+               }\r
        }\r
 \r
        public void startup() {\r
@@ -393,37 +381,34 @@ public class NexioDispatcher implements ClipEventListener {
                        logger.catching(e);\r
                        return;\r
                }\r
-               logger.info("NEXIO server connected");\r
-\r
-               this.progressListenerList = new EventListenerList();\r
 \r
-               boolean disableNexio = Boolean.parseBoolean(System.getProperty(NEXIO_DISABLE));\r
-               if (disableNexio)\r
-                       return;\r
-\r
-               this.dropAllClipsFromMongo();\r
-               this.ensureIndexes();\r
+               if (!disabled) {\r
+                       this.dropAllClipsFromMongo();\r
+                       this.ensureIndexes();\r
+               }\r
 \r
                boolean[] useMOSGateway = { Boolean.parseBoolean(System.getProperty(NEXIO_USE_MOS_GATEWAY)) };\r
-               executor.submit(() -> {\r
+\r
+               worker = new Thread(() -> {\r
                        try {\r
-                               if (useMOSGateway[0]) {\r
-                                       NexioDataMiner dm = new NexioDataMiner();\r
-                                       dm.transferClips();\r
-                               } else {\r
-                                       copyClipsIntoMongo();\r
+                               logger.info("Initial clip import started");\r
+                               if (!disabled) {\r
+                                       if (useMOSGateway[0]) {\r
+                                               NexioDataMiner dm = new NexioDataMiner();\r
+                                               dm.transferClips();\r
+                                       } else {\r
+                                               copyClipsIntoMongo();\r
+                                       }\r
                                }\r
-                               NexioDispatcher.this.controller.getMediabase().startMediaListener();\r
-                               NexioDispatcher.this.controller.getMediabase().getMediaListener().addClipEventListener(NexioDispatcher.this);\r
+                               logger.info("Initial clip import completed");\r
+                               Mediabase mediabase = NexioDispatcher.this.controller.getMediabase();\r
+                               mediaListener = mediabase.createMediaListener(disabled, NexioDispatcher.this);\r
+                               mediaListener.startListener();\r
                        } catch (Exception e) {\r
                                logger.catching(e);\r
                        }\r
                });\r
-       }\r
-\r
-       private String toUTF8(String iso88592) throws UnsupportedEncodingException {\r
-               byte[] bytes = iso88592.getBytes("ISO-8859-2");\r
-               return new String(bytes, "UTF-8");\r
+               worker.start();\r
        }\r
 \r
 }\r
index d7e4512696377256655f672183d65cd574393116..a3002c3dc83064d97e3d3f87a78a41fd1d55786d 100644 (file)
@@ -2,4 +2,6 @@ package user.commons.nexio.api;
 \r
 public interface ClipEventListener {\r
        public void clipEventPerformed(ClipEvent evt);\r
+\r
+       void restart();\r
 }\r
index c8ae94bf4e568a77997c192a4f5e116f6667bae3..739c99fb9566205495a02bf14ac0ef82e4325d62 100644 (file)
@@ -1,9 +1,12 @@
 package user.commons.nexio.api;
 
-import user.commons.nexio.server.protocol.*;
 import java.io.IOException;
 import java.net.UnknownHostException;
 
+import user.commons.nexio.server.protocol.Connection;
+import user.commons.nexio.server.protocol.NexioServerProtocolImpl;
+import user.commons.nexio.server.protocol.TCPConnection;
+
 public class Controller {
 
        private Connection connection = null;
@@ -25,24 +28,27 @@ public class Controller {
                mediabase = new MediabaseImpl(new NexioServerProtocolImpl(connection));
        }
 
-       public void disconnect() throws IOException {
-               connection.disconnect();
+       public void disconnect() {
+               try {
+                       connection.disconnect();
+               } catch (Exception e) {
+               }
        }
 
-       public Mediabase getMediabase() {
-               return mediabase;
+       public Connection getConnection() {
+               return this.connection;
        }
 
-       public String getHost(){
+       public String getHost() {
                return this.host;
        }
-       
-       public int getPort(){
-               return this.port;
+
+       public Mediabase getMediabase() {
+               return mediabase;
        }
-       
-       public Connection getConnection(){
-               return this.connection;
+
+       public int getPort() {
+               return this.port;
        }
-       
+
 }
index e9c321d7f867cd9d50396f1439d5d1b047cb6432..34326026fa52c8873445fe4be67c1b363fa31b60 100644 (file)
@@ -19,7 +19,7 @@ import user.commons.nexio.server.protocol.TCPConnection;
  * @author robi\r
  */\r
 \r
-public class MediaListener implements Runnable {\r
+public class MediaListener {\r
 \r
        static private final char[] hexArray = "0123456789ABCDEF".toCharArray();\r
        static private final Logger logger = LogManager.getLogger();\r
@@ -59,22 +59,16 @@ public class MediaListener implements Runnable {
        }\r
 \r
        private ArrayList<ClipEventListener> clipEventListeners = new ArrayList<ClipEventListener>();\r
-       private boolean isRunning = false;\r
-\r
        private Mediabase mediaBase = null;\r
        private int nexioPort = 557;\r
        private String nexioHost = null;\r
-\r
        private Connection connection = null;\r
-\r
        private ArrayList<Integer> notificationList = new ArrayList<Integer>();\r
 \r
-       //KONSTRUKTOR\r
        public MediaListener(Mediabase _mediaBase, String _nexioHost, int _nexioPort) {\r
                this.mediaBase = _mediaBase;\r
                this.nexioHost = _nexioHost;\r
                this.nexioPort = _nexioPort;\r
-               startListener();\r
        }\r
 \r
        public void addClipEventListener(ClipEventListener listener) {\r
@@ -107,25 +101,48 @@ public class MediaListener implements Runnable {
 \r
        private void createNexioConnection() throws Exception {\r
                this.connection = TCPConnection.getInstance(this.nexioHost, this.nexioPort);\r
-               logger.info("Nexio MediaListener is connected to NEXIO " + this.nexioHost + " : " + this.nexioPort);\r
+               logger.info("NEXIO MediaListener is connected to " + this.nexioHost + ":" + this.nexioPort);\r
+       }\r
+\r
+       public void disconnect() {\r
+               try {\r
+                       if (connection != null)\r
+                               connection.disconnect();\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
+               }\r
        }\r
 \r
        private void fireEvent(String idString, int notificationNumber) throws Exception {\r
-               Id id = new Id(idString);\r
                ClipEvent evt = null;\r
-               if (notificationNumber == NN_ID_ADDED) {\r
-                       evt = new ClipEvent(mediaBase.getClip(id), ClipEventType.CLIP_ADDED);\r
-               } else if (notificationNumber == NN_ID_DELETED) {\r
-                       Clip deletedClip = new ClipImpl(mediaBase.getProtocol(), id);\r
-                       evt = new ClipEvent(deletedClip, ClipEventType.CLIP_DELETED);\r
-               } else if (notificationNumber == NN_LISTENER_RESTART) {\r
+               if (notificationNumber == NN_LISTENER_RESTART) {\r
                        evt = new ClipEvent(null, ClipEventType.LISTENER_RESTART_NEEDED);\r
+               } else {\r
+                       Id id = new Id(idString);\r
+                       if (notificationNumber == NN_ID_ADDED) {\r
+                               evt = new ClipEvent(mediaBase.getClip(id), ClipEventType.CLIP_ADDED);\r
+                       } else if (notificationNumber == NN_ID_DELETED) {\r
+                               Clip deletedClip = new ClipImpl(mediaBase.getProtocol(), id);\r
+                               evt = new ClipEvent(deletedClip, ClipEventType.CLIP_DELETED);\r
+                       }\r
                }\r
+\r
                for (ClipEventListener cel : this.clipEventListeners) {\r
                        cel.clipEventPerformed(evt);\r
                }\r
        }\r
 \r
+       private void forceRestart() {\r
+               logger.info("MediaListener stopping...");\r
+               try {\r
+                       fireEvent(null, NN_LISTENER_RESTART);\r
+                       //                      if (this.connection != null)\r
+                       //                              this.connection.disconnect();\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
+               }\r
+       }\r
+\r
        private void handleNotification(int notificationNumber) throws Exception {\r
                //LIST_FIRST_ID_LIST\r
                /*\r
@@ -149,138 +166,83 @@ public class MediaListener implements Runnable {
 \r
        }\r
 \r
-       private byte[] readBytes(int numberOfBytes) throws Exception {\r
-               byte[] ret = new byte[numberOfBytes];\r
-               try {\r
-                       for (int c = 0; c < numberOfBytes; c++) {\r
-                               ret[c] = (byte) this.connection.read();\r
-                       }\r
-               } catch (Exception e) {\r
-                       restartListener();\r
-                       throw e;\r
-               }\r
-               return ret;\r
-       }\r
-\r
-       private byte[] readBytesOLD(int numberOfBytes) throws Exception {\r
-               try {\r
-                       byte[] ret = new byte[numberOfBytes];\r
-                       this.connection.read(ret, 0, numberOfBytes);\r
-                       return ret;\r
-               } catch (Exception e) {\r
-                       restartListener();\r
-                       throw e;\r
-               }\r
-       }\r
-\r
-       public void removeClipEventListener(ClipEventListener listener) {\r
-               this.clipEventListeners.remove(listener);\r
-       }\r
-\r
-       private void restartListener() throws Exception {\r
-               this.isRunning = false;\r
-               Thread.sleep(3000);\r
-               try {\r
-                       Thread.currentThread().interrupt();\r
-               } catch (Exception e) {\r
-               }\r
-               try {\r
-                       if (this.connection != null) {\r
-                               this.connection.disconnect();\r
-                       }\r
-               } catch (Exception e) {\r
-               }\r
-               //new connection / new thread\r
-               //szóljunk a dispatcher-nek, hogy inicializálja újra magát\r
-               //fireEvent(null, NN_LISTENER_RESTART);\r
-               startListener();\r
-       }\r
-\r
-       @Override\r
-       public void run() {\r
+       private void listen() {\r
                try {\r
                        //SEND CHANGE NOTIFICATION REQ\r
                        writeBytes(CHANGE_NOTIFICATION_REQ);\r
 \r
                        //ACK\r
                        byte[] buffer = readBytes(2);\r
-                       logger.info("Nexio MediaListener is waiting for events..");\r
-\r
-                       while (isRunning) {\r
-                               try {\r
-\r
-                                       //BLOKKOLVA addig olvassa fel es gyujti a notification-oket amig mas adat nem jon.\r
-                                       //az elso alkalommal amikor nem notification-t kap, visszater.\r
-                                       buffer = collectNotifications(false);\r
-\r
-                                       //LIST_FIRST_ID_LIST response\r
-                                       if (LIST_FIRST_ID_LIST_FOUND.equals(bytesToHex(buffer))) {\r
-                                               int notificationNumber = notificationList.get(0);\r
-                                               notificationList.remove(0);\r
-\r
-                                               //read first id\r
-                                               buffer = readBytes(8);\r
-                                               String stringId = new String(buffer);\r
-                                               logger.debug("Nexio MediaListener first id: " + stringId);\r
+                       logger.info("NEXIO MediaListener listeninig");\r
+\r
+                       while (true) {\r
+                               //BLOKKOLVA addig olvassa fel es gyujti a notification-oket amig mas adat nem jon.\r
+                               //az elso alkalommal amikor nem notification-t kap, visszater.\r
+                               buffer = collectNotifications(false);\r
+\r
+                               //LIST_FIRST_ID_LIST response\r
+                               if (LIST_FIRST_ID_LIST_FOUND.equals(bytesToHex(buffer))) {\r
+                                       int notificationNumber = notificationList.get(0);\r
+                                       notificationList.remove(0);\r
+\r
+                                       //read first id\r
+                                       buffer = readBytes(8);\r
+                                       String stringId = new String(buffer);\r
+                                       logger.debug("Nexio MediaListener first id: " + stringId);\r
+                                       fireEvent(stringId, notificationNumber);\r
+\r
+                                       //read next ids\r
+                                       writeBytes(LIST_NEXT_ID_LIST);\r
+                                       //for (buffer = readBytes(2); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer)) && isRunning; buffer = readBytes(2)) {\r
+                                       for (buffer = collectNotifications(true); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer)); buffer = collectNotifications(true)) {\r
+\r
+                                               byte[] idBuffer = readBytes(8);\r
+                                               stringId = new String(idBuffer);\r
+                                               logger.debug("Nexio MediaListener next id: " + stringId);\r
                                                fireEvent(stringId, notificationNumber);\r
 \r
-                                               //read next ids\r
                                                writeBytes(LIST_NEXT_ID_LIST);\r
-                                               //for (buffer = readBytes(2); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer)) && isRunning; buffer = readBytes(2)) {\r
-                                               for (buffer = collectNotifications(true); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer))\r
-                                                               && isRunning; buffer = collectNotifications(true)) {\r
-\r
-                                                       byte[] idBuffer = readBytes(8);\r
-                                                       stringId = new String(idBuffer);\r
-                                                       logger.debug("Nexio MediaListener next id: " + stringId);\r
-                                                       fireEvent(stringId, notificationNumber);\r
-\r
-                                                       writeBytes(LIST_NEXT_ID_LIST);\r
-                                               }\r
-                                               logger.debug("Nexio MediaListener end of id list: " + bytesToHex(buffer));\r
-                                               //SEND ACK\r
-                                               writeBytes(ACK);\r
-\r
-                                       } else if (LIST_FIRST_ID_LIST_NOT_FOUND.equals(bytesToHex(buffer))) {\r
-                                               notificationList.remove(0);\r
-                                               logger.debug("Nexio MediaListener LIST_FIRST_ID_LIST ID not found!");\r
-                                       } else {\r
-                                               logger.debug("Nexio MediaListener unknown answer has arrived for LIST_FIRST_ID_LIST:  " + bytesToHex(buffer));\r
                                        }\r
-                               } catch (Exception exc) {\r
-                                       logger.error("", exc);\r
+                                       logger.debug("Nexio MediaListener end of id list: " + bytesToHex(buffer));\r
+                                       //SEND ACK\r
+                                       writeBytes(ACK);\r
+\r
+                               } else if (LIST_FIRST_ID_LIST_NOT_FOUND.equals(bytesToHex(buffer))) {\r
+                                       notificationList.remove(0);\r
+                                       logger.debug("Nexio MediaListener LIST_FIRST_ID_LIST ID not found!");\r
+                               } else {\r
+                                       logger.debug("Nexio MediaListener unknown answer has arrived for LIST_FIRST_ID_LIST:  " + bytesToHex(buffer));\r
                                }\r
                        }\r
-                       this.connection.disconnect();\r
                } catch (Exception e) {\r
-                       logger.error("", e);\r
+                       logger.catching(e);\r
+                       forceRestart();\r
                }\r
        }\r
 \r
-       public void startListener() {\r
-               try {\r
-                       createNexioConnection();\r
-                       this.isRunning = true;\r
-                       Thread t = new Thread(this, "MediaListener");\r
-                       t.start();\r
-                       logger.info("Nexio MediaListener is starting...");\r
-               } catch (Exception exc) {\r
-                       logger.error("", exc);\r
+       private byte[] readBytes(int numberOfBytes) throws Exception {\r
+               byte[] ret = new byte[numberOfBytes];\r
+               for (int c = 0; c < numberOfBytes; c++) {\r
+                       ret[c] = (byte) this.connection.read();\r
                }\r
+               return ret;\r
        }\r
 \r
-       public void stopListener() {\r
-               this.isRunning = false;\r
+       public void removeClipEventListener(ClipEventListener listener) {\r
+               this.clipEventListeners.remove(listener);\r
        }\r
 \r
-       private void writeBytes(byte[] toWrite) throws Exception {\r
+       public void startListener() {\r
                try {\r
-                       this.connection.write(toWrite);\r
-                       this.connection.flush();\r
+                       createNexioConnection();\r
+                       listen();\r
                } catch (Exception e) {\r
-                       restartListener();\r
-                       throw e;\r
+                       logger.catching(e);\r
                }\r
        }\r
 \r
+       private void writeBytes(byte[] toWrite) throws Exception {\r
+               this.connection.write(toWrite);\r
+               this.connection.flush();\r
+       }\r
 }\r
index a5f8a6e74d7f9b555e682b881af908710426b04f..b01ce27658aef199e5d4e8913a7f4c58345ce83c 100644 (file)
@@ -1,21 +1,23 @@
 package user.commons.nexio.api;
 
-import user.commons.nexio.server.protocol.*;
 import java.io.IOException;
 import java.util.Iterator;
 
+import user.commons.nexio.server.protocol.Id;
+import user.commons.nexio.server.protocol.NexioServerProtocol;
+import user.commons.nexio.server.protocol.ProtocolException;
+import user.commons.nexio.server.protocol.Xid;
+
 public interface Mediabase {
 
+       public MediaListener createMediaListener(boolean disabled, ClipEventListener listener);
+
        public Clip getClip(Id id) throws IOException, ProtocolException;
 
        public Clip getClip(Xid xid) throws IOException, ProtocolException;
 
        public Iterator<Clip> getClips() throws IOException, ProtocolException;
 
-       public MediaListener getMediaListener();
-       
-       public void startMediaListener();
-       
        public NexioServerProtocol getProtocol();
-       
+
 }
index 12369a82ab9b85f9b1ba645af68110dbff939a7f..4c841bc8f6f831bb256f3706c896fdd8a51d8b17 100644 (file)
@@ -71,6 +71,13 @@ class MediabaseImpl implements Mediabase {
                }
        }
 
+       @Override
+       public MediaListener createMediaListener(boolean disabled, ClipEventListener listener) {
+               mediaListener = new MediaListener(this, protocol.getConnection().getHost(), protocol.getConnection().getPort());
+               mediaListener.addClipEventListener(listener);
+               return mediaListener;
+       }
+
        @Override
        public Clip getClip(Id id) throws IOException, ProtocolException {
                if (id == null) {
@@ -97,21 +104,9 @@ class MediabaseImpl implements Mediabase {
                return new Itr();
        }
 
-       @Override
-       public MediaListener getMediaListener() {
-               return this.mediaListener;
-       }
-
        @Override
        public NexioServerProtocol getProtocol() {
                return this.protocol;
        }
 
-       @Override
-       public void startMediaListener() {
-               if (this.mediaListener == null) {
-                       this.mediaListener = new MediaListener(this, protocol.getConnection().getHost(), protocol.getConnection().getPort());
-               }
-       }
-
 }
index 8eebed25e53b96b0ea433782e7930a1fa4416153..a197e622bd99670a69cd690ecdfe1448e0e9182a 100644 (file)
 package user.commons.nexio.api.samples;
 
-import user.commons.nexio.server.protocol.*;
-import user.commons.nexio.api.*;
-
 import java.io.IOException;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Iterator;
 
 import org.apache.logging.log4j.LogManager;
 import org.apache.logging.log4j.Logger;
 
-public class ListMetabaseContents implements ClipEventListener{
-       
+import user.commons.nexio.api.ClipEvent;
+import user.commons.nexio.api.ClipEventListener;
+import user.commons.nexio.api.ClipNotFoundException;
+import user.commons.nexio.api.Mediabase;
+import user.commons.nexio.server.protocol.Connection;
+import user.commons.nexio.server.protocol.Id;
+import user.commons.nexio.server.protocol.ProtocolException;
+import user.commons.nexio.server.protocol.TCPConnection;
+
+public class ListMetabaseContents implements ClipEventListener {
+
        static private final char[] hexArray = "0123456789ABCDEF".toCharArray();
        static private final Logger logger = LogManager.getLogger();
        //MASK REQ                      RESP_NOT_NUM
        //00 00 00 01           0x00                    IDs in Added List               BC=0x01, NN=0x00, DATA=none
        //00 00 00 02           0x01                    IDs in Deleted List             BC=0x01, NN=0x01, DATA=none                     //                        1+2
-       static private final byte[] CHANGE_NOTIFICATION_REQ = { (byte) 0xC4, (byte)0xA5, 0,0,0,0x03};   //C4A5 + MASK=ADD+DELETE
+       static private final byte[] CHANGE_NOTIFICATION_REQ = { (byte) 0xC4, (byte) 0xA5, 0, 0, 0, 0x03 }; //C4A5 + MASK=ADD+DELETE
        //10 01 response immediately
-       static private final byte[] ACK = { (byte) 0x10, (byte)0x01};
-       //CF A6 BC NN DATA              NN=0 -> IDs are in added list, NN=1 -> IDs are in deleted list  
-       static private final byte[] CHANGE_NOTIFICATION_RESP = { (byte) 0xCF, (byte)0xA6};
-       //List First ID List (C1 4C)    
-       static private final byte[] LIST_FIRST_ID_LIST_ADDED =  { (byte) 0xC1, (byte)0x4C, (byte)0x02};         //2 added, 3 deleted
-       static private final byte[] LIST_FIRST_ID_LIST_DELETED = { (byte) 0xC1, (byte)0x4C, (byte)0x03};        //2 added, 3 deleted
-       //List First ID List (C0 4D)    
-       static private final byte[] LIST_NEXT_ID_LIST = { (byte) 0xC0, (byte)0x4D};
-
-       
+       static private final byte[] ACK = { (byte) 0x10, (byte) 0x01 };
+       //CF A6 BC NN DATA              NN=0 -> IDs are in added list, NN=1 -> IDs are in deleted list
+       static private final byte[] CHANGE_NOTIFICATION_RESP = { (byte) 0xCF, (byte) 0xA6 };
+       //List First ID List (C1 4C)
+       static private final byte[] LIST_FIRST_ID_LIST_ADDED = { (byte) 0xC1, (byte) 0x4C, (byte) 0x02 }; //2 added, 3 deleted
+       static private final byte[] LIST_FIRST_ID_LIST_DELETED = { (byte) 0xC1, (byte) 0x4C, (byte) 0x03 }; //2 added, 3 deleted
+       //List First ID List (C0 4D)
+       static private final byte[] LIST_NEXT_ID_LIST = { (byte) 0xC0, (byte) 0x4D };
+
        static private final String LIST_FIRST_ID_LIST_NOT_FOUND = "D04C";
        static private final String LIST_NEXT_ID_LIST_NOT_FOUND = "D04D";
-       
+
        static private final String LIST_FIRST_ID_LIST_FOUND = "D84C";
        static private final String LIST_NEXT_ID_LIST_FOUND = "D84D";
        //static private final String LIST_FIRST_ID_LIST_FOUND = "DF4C";        //0x22, 0x23 foundhoz
        //static private final String LIST_NEXT_ID_LIST_FOUND = "D84D"; //0x22, 0x23 foundhoz
-       
-       
-       static private final int  NN_ID_ADDED = 0;
-       static private final int  NN_ID_DELETED = 1;
-       
+
+       static private final int NN_ID_ADDED = 0;
+       static private final int NN_ID_DELETED = 1;
+
+       public static String bytesToHex(byte[] bytes) {
+               char[] hexChars = new char[bytes.length * 2];
+               for (int j = 0; j < bytes.length; j++) {
+                       int v = bytes[j] & 0xFF;
+                       hexChars[j * 2] = hexArray[v >>> 4];
+                       hexChars[j * 2 + 1] = hexArray[v & 0x0F];
+               }
+               return new String(hexChars);
+       }
+
+       private static Id getNextId(Connection connection) throws IOException, ProtocolException {
+               byte[] buffer = new byte[8];
+               int c = connection.read(buffer, 0, 8);
+               if (c != 8) {
+                       return null; //throw getException_InvalidResponseLength(c, 8, 8);
+               } else {
+                       return new Id(new String(buffer));
+               }
+       }
+
+       private static int getNOFIds(Connection connection) throws IOException, ProtocolException {
+               byte[] buffer = new byte[2];
+               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
+               int nofIds = ((buffer[0] << 8) & 0xFF00) | (buffer[1] & 0x00FF); //00000001 10010000
+               return nofIds;
+       }
+
+       public static void main(String[] args) throws UnknownHostException, IOException, ProtocolException, ClipNotFoundException {
+               ListMetabaseContents lmc = new ListMetabaseContents();
+
+               /*              
+                               
+                               
+                               //MASK REQ                      RESP_NOT_NUM
+                               //00 00 00 01           0x00                    IDs in Added List               BC=0x01, NN=0x00, DATA=none
+                               //00 00 00 02           0x01                    IDs in Deleted List             BC=0x01, NN=0x01, DATA=none
+                               byte[] CHANGE_NOTIFICATION_REQ = { (byte) 0xC4, (byte)0xA5, 0,0,0,0x03};        //+C4A5 + MASK
+               
+                               //10 01 response immediately
+                               byte[] ACK = { (byte) 0x10, (byte)0x01};
+               
+                               //CF A6 BC NN DATA              NN=0 -> IDs are in added list, NN=1 -> IDs are in deleted list  
+                               byte[] CHANGE_NOTIFICATION_RESP = { (byte) 0xCF, (byte)0xA6};
+               
+                               //List First ID List (C1 4C)    
+                               byte[] LIST_FIRST_ID_LIST_ADDED =       { (byte) 0xC1, (byte)0x4C, (byte)0x02}; //2 added, 3 deleted
+                               byte[] LIST_FIRST_ID_LIST_DELETED = { (byte) 0xC1, (byte)0x4C, (byte)0x03};     //2 added, 3 deleted
+               
+                               //List First ID List (C0 4D)    
+                               byte[] LIST_NEXT_ID_LIST = { (byte) 0xC0, (byte)0x4D};
+                               
+                               
+                               Connection connection = TCPConnection.getInstance(NEXIO_HOST, 557);
+               //              connection.write(ID_LIST);
+               //              connection.flush();
+               
+                       connection.write(CHANGE_NOTIFICATION_REQ);
+                       connection.flush();
+                       //ACK
+                       byte[] buffer = new byte[2];
+                       int c = connection.read(buffer, 0, 2);
+                       
+                       
+                       while("1".equals("1")){
+                       
+                               //CHANGE_NOTIFICATION_RESP (blocking read)
+                               buffer = new byte[4];
+                               c = connection.read(buffer,0,4);                                //CFA6 BC NN -> 0=added, 1=deleted
+                               System.out.println("change notification resp: " + bytesToHex(buffer));
+                               
+                               //ACK sending back
+                               connection.write(ACK);
+                               connection.flush();
+                       
+                               //LIST_FIRST_ID_LIST
+                               
+                               //0x01  Main ID Handle List     D8 4C ID
+                               //0x02  ID Handles Added List   D8 4C ID
+                               //0x03  ID Handles Deleted List D8 4C ID
+                               //0x11  Main Extended ID List   DF 4C BC XID *
+                               //0x12  Extended IDs Added List DF 4C BC XID *
+                               //0x13  Extended IDs Deleted List       DF 4C BC XID *
+                               //0x21  Main ID Handle/Extended ID List DF 4C BC ID XID *
+                               //0x22  ID Handles/Extended IDs Added List      DF 4C BC ID XID *
+                               //0x23  ID Handles/Extended IDs Deleted List    DF 4C BC ID XID *
+                               
+                               if(buffer[3] == 0){
+                                       connection.write(LIST_FIRST_ID_LIST_ADDED);
+                                       System.out.println("NN ADDED");
+                               }else
+                               if(buffer[3] == 1){
+                                       connection.write(LIST_FIRST_ID_LIST_DELETED);
+                                       System.out.println("NN DELETED");
+                               }
+                               connection.flush();
+                       
+                               //READ FIRST ID
+                               buffer = new byte[2];
+                               c = connection.read(buffer, 0, 2);
+                               if("D84C".equals(bytesToHex(buffer))){
+                                       System.out.println("reading first id...");
+                                       
+                                       //added or deleted
+                                       buffer = new byte[8];
+                                       c = connection.read(buffer, 0, 8);
+                                       System.out.println("FIRST ID: " + new String(buffer));
+                               
+                                       //C0 4D List Next ID List
+                                       connection.write(LIST_NEXT_ID_LIST);
+                                       connection.flush();
+                                       
+                                       buffer = new byte[2];
+                                       //D04D amikor elfogy
+                                       for(connection.read(buffer, 0, 2);      bytesToHex(buffer).equals("D84D");      connection.read(buffer, 0, 2)){
+                       
+                                               buffer = new byte[8];
+                                               c = connection.read(buffer, 0, 8);
+                                               System.out.println("NEXT ID: " + new String(buffer));
+                                       
+                                               connection.write(LIST_NEXT_ID_LIST);
+                                               connection.flush();
+                                               
+                                               buffer = new byte[2];
+                                       }
+                                       //System.out.println("LIST_NEXT_ID_LIST RESP: " + bytesToHex(buffer));
+                               }else
+                               if(bytesToHex(buffer).equals("D04C")){
+                                                       System.out.println("No one found for first ID!");
+                               }else{
+                                       System.out.println("Error in list first id list response: " + bytesToHex( buffer));
+                               }
+                       }
+                       
+                       
+                               //int i = connection.read();
+                               connection.disconnect();
+               */
+       }
+
        private ArrayList<ClipEventListener> clipEventListeners = new ArrayList<ClipEventListener>();
        private boolean isRunning = false;
+
        private Mediabase mediaBase = null;
 
        private int nexioPort = 557;
-       private String nexioHost = "10.228.43.38";      //echo: "10.10.1.55";   vmware: "10.228.43.18"
+
+       private String nexioHost = "10.228.43.38"; //echo: "10.10.1.55";        vmware: "10.228.43.18"
+
        private Connection connection = null;
 
-       
-       
        //KONSTRUKTOR
-       public ListMetabaseContents(){
-               try{
+       public ListMetabaseContents() {
+               try {
                        this.isRunning = true;
                        createNexioConnection();
                        this.testAddDelete();
-                       
-/*                     
-                       Controller controller = new Controller(nexioHost);
-                       controller.connect();
-                       System.out.println("Connected.");
-*/
-                       
-/*
-                       Iterator<Clip> clips = mediabase.getClips();
-                       while (clips.hasNext()) {
-                               Clip clip = clips.next();
-                               // Unique internal ID
-                               String id = clip.getId().get();
-                               // Extended ID (Filename)
-                               String xid = clip.getXid().get();
-                               // Number of frames
-                               long duration = clip.getDuration();
-                               // Timestamp of last modification
-                               Calendar modifiedTimestamp = clip.getModifiedTimestamp();
-                               //Video Format
-                               int videoFormat = clip.getVideoFormat();
-                               //Video Bitrate
-                               int videoBitrate = clip.getVideoBitrate();
-                                                                               
-                               System.out.println(String.format("ID = '%s'\tXID = '%s'\tDuration = '%s'\tModified = '%s'\tVideoFormat = '%s'\tVideoBitrate = '%s'",
-                                               id, xid, duration, modifiedTimestamp.getTime(), videoFormat, videoBitrate));
-                       }
 
-                       //Clip clip = mediabase.getClip(new Xid("xdcam-pal-d10-imx30-8"));
-                       //long duration2 = clip.getDuration();
-                       //System.out.println(clip + " dur: "+  duration2);
-*/                     
+                       /*                      
+                                               Controller controller = new Controller(nexioHost);
+                                               controller.connect();
+                                               System.out.println("Connected.");
+                       */
+
+                       /*
+                                               Iterator<Clip> clips = mediabase.getClips();
+                                               while (clips.hasNext()) {
+                                                       Clip clip = clips.next();
+                                                       // Unique internal ID
+                                                       String id = clip.getId().get();
+                                                       // Extended ID (Filename)
+                                                       String xid = clip.getXid().get();
+                                                       // Number of frames
+                                                       long duration = clip.getDuration();
+                                                       // Timestamp of last modification
+                                                       Calendar modifiedTimestamp = clip.getModifiedTimestamp();
+                                                       //Video Format
+                                                       int videoFormat = clip.getVideoFormat();
+                                                       //Video Bitrate
+                                                       int videoBitrate = clip.getVideoBitrate();
+                                                                                                       
+                                                       System.out.println(String.format("ID = '%s'\tXID = '%s'\tDuration = '%s'\tModified = '%s'\tVideoFormat = '%s'\tVideoBitrate = '%s'",
+                                                                       id, xid, duration, modifiedTimestamp.getTime(), videoFormat, videoBitrate));
+                                               }
                        
-               }catch(Exception exc){
+                                               //Clip clip = mediabase.getClip(new Xid("xdcam-pal-d10-imx30-8"));
+                                               //long duration2 = clip.getDuration();
+                                               //System.out.println(clip + " dur: "+  duration2);
+                       */
+
+               } catch (Exception exc) {
                        exc.printStackTrace();
                }
        }
-       
-       public void clipEventPerformed(ClipEvent evt){
+
+       @Override
+       public void clipEventPerformed(ClipEvent evt) {
                System.out.println("clipEventPerformed " + evt.getEventType() + ", " + evt.getClip());
        }
-       
-       
-       public void testAddDelete(){
-               try{
+
+       private void createNexioConnection() throws Exception {
+               this.connection = TCPConnection.getInstance(this.nexioHost, this.nexioPort);
+               System.out.println("Nexio MediaListener is connected to NEXIO " + this.nexioHost + " : " + this.nexioPort);
+       }
+
+       private byte[] readBytes(int numberOfBytes) throws Exception {
+               try {
+                       byte[] ret = new byte[numberOfBytes];
+                       this.connection.read(ret, 0, numberOfBytes);
+                       return ret;
+               } catch (Exception e) {
+                       //restartListener();
+                       throw e;
+               }
+       }
+
+       @Override
+       public void restart() {
+               // TODO Auto-generated method stub
+
+       }
+
+       public void testAddDelete() {
+               try {
                        //SEND CHANGE NOTIFICATION REQ
                        writeBytes(CHANGE_NOTIFICATION_REQ);
-                       
+
                        //ACK
                        byte[] buffer = readBytes(2);
                        System.out.println("Nexio MediaListener is waiting for events..");
-                       
-                       while(isRunning){
-                               try{
+
+                       while (isRunning) {
+                               try {
                                        //CHANGE_NOTIFICATION_RESP (BLOCKING READ!)
                                        //TEST CODE
-                                       if(buffer.length == 2){
-                                               buffer = readBytes(4);                          //CFA6  BC      NN->0=added, 1=deleted  
+                                       if (buffer.length == 2) {
+                                               buffer = readBytes(4); //CFA6   BC      NN->0=added, 1=deleted
                                        }
-                                       
+
                                        int notificationNumber = buffer[3];
                                        System.out.println("Nexio MediaListener notification: " + bytesToHex(buffer));
-                                       
+
                                        //SEND ACK
-//                                     writeBytes(ACK);
-                               
+                                       //                                      writeBytes(ACK);
+
                                        //LIST_FIRST_ID_LIST
                                        /*
                                                0x01    Main ID Handle List     D8 4C ID
@@ -138,272 +306,101 @@ public class ListMetabaseContents implements ClipEventListener{
                                                0x22    ID Handles/Extended IDs Added List      DF 4C BC ID XID *
                                                0x23    ID Handles/Extended IDs Deleted List    DF 4C BC ID XID *
                                        */
-                                       if(notificationNumber == NN_ID_ADDED){
+                                       if (notificationNumber == NN_ID_ADDED) {
                                                writeBytes(LIST_FIRST_ID_LIST_ADDED);
-                                       }else
-                                       if(notificationNumber == NN_ID_DELETED){
-writeBytes(ACK);                                               
+                                       } else if (notificationNumber == NN_ID_DELETED) {
+                                               writeBytes(ACK);
                                                writeBytes(LIST_FIRST_ID_LIST_DELETED);
                                        }
-                               
+
                                        //LIST_FIRST_ID_LIST response
                                        buffer = readBytes(2);
-                                       if(LIST_FIRST_ID_LIST_FOUND.equals(bytesToHex(buffer))){
-/*
*                                             //extended id version 0x22, 0x23                                                
-                                               //found 2, BC 1, ID 8, XID {BC-8}
-                                               buffer = readBytes(1);
-                                               int bc = buffer[0];
-                                               buffer = readBytes(8);
-                                               String stringId = new String(buffer);
-                                               buffer = readBytes(bc-8);
-                                               String xid = new String(buffer);
-                                               System.out.println("Nexio MediaListener first id: " + stringId + ", xid: " + xid);
-*/                                             
-                                               
-                                               //found 2, ID 8
+                                       if (LIST_FIRST_ID_LIST_FOUND.equals(bytesToHex(buffer))) {
+                                               /*
                                               *                                              //extended id version 0x22, 0x23                                                
+                                                                                               //found 2, BC 1, ID 8, XID {BC-8}
+                                                                                               buffer = readBytes(1);
+                                                                                               int bc = buffer[0];
+                                                                                               buffer = readBytes(8);
+                                                                                               String stringId = new String(buffer);
+                                                                                               buffer = readBytes(bc-8);
+                                                                                               String xid = new String(buffer);
+                                                                                               System.out.println("Nexio MediaListener first id: " + stringId + ", xid: " + xid);
+                                               */
+
+                                               //found 2, ID 8
                                                //read first id
                                                buffer = readBytes(8);
                                                String stringId = new String(buffer);
                                                System.out.println("Nexio MediaListener first id: " + stringId);
                                                //fireEvent(stringId, notificationNumber);
-                                               
+
                                                //read next ids
                                                writeBytes(LIST_NEXT_ID_LIST);
-                                               
-                                               for(buffer=readBytes(2); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer)) && isRunning; buffer=readBytes(2)){
-                                                       
+
+                                               for (buffer = readBytes(2); LIST_NEXT_ID_LIST_FOUND.equals(bytesToHex(buffer)) && isRunning; buffer = readBytes(2)) {
+
                                                        byte[] idBuffer = readBytes(8);
                                                        stringId = new String(idBuffer);
                                                        System.out.println("Nexio MediaListener next id: " + stringId);
                                                        //fireEvent(stringId, notificationNumber);
-                               
-/*
-                                                       //extended id 0x22, 0x23 versions
-                                                       //found 2, BC 1, ID 8, XID {BC-8}
-                                                       buffer = readBytes(1);
-                                                       bc = buffer[0];
-                                                       buffer = readBytes(8);
-                                                       stringId = new String(buffer);
-                                                       buffer = readBytes(bc-8);
-                                                       xid = new String(buffer);
-                                                       System.out.println("Nexio MediaListener next id: " + stringId + ", xid: " + xid);
-*/                                                     
+
+                                                       /*
+                                                                                                               //extended id 0x22, 0x23 versions
+                                                                                                               //found 2, BC 1, ID 8, XID {BC-8}
+                                                                                                               buffer = readBytes(1);
+                                                                                                               bc = buffer[0];
+                                                                                                               buffer = readBytes(8);
+                                                                                                               stringId = new String(buffer);
+                                                                                                               buffer = readBytes(bc-8);
+                                                                                                               xid = new String(buffer);
+                                                                                                               System.out.println("Nexio MediaListener next id: " + stringId + ", xid: " + xid);
+                                                       */
                                                        writeBytes(LIST_NEXT_ID_LIST);
                                                }
                                                System.out.println("Nexio MediaListener end of id list: " + bytesToHex(buffer));
 
-writeBytes(ACK);                                               
-                                               
+                                               writeBytes(ACK);
+
                                                //TEST CODE
-                                               if(bytesToHex(buffer).equals("CFA6")){
+                                               if (bytesToHex(buffer).equals("CFA6")) {
                                                        buffer = readBytes(2);
-                                                       byte[] newBuffer = new byte[]{(byte)0xCF,(byte)0xA6, buffer[0], buffer[1]};
+                                                       byte[] newBuffer = new byte[] { (byte) 0xCF, (byte) 0xA6, buffer[0], buffer[1] };
                                                        buffer = newBuffer;
                                                }
-                                               
-                                                       
-                                       }else
-                                       if(LIST_FIRST_ID_LIST_NOT_FOUND.equals(bytesToHex(buffer))){
+
+                                       } else if (LIST_FIRST_ID_LIST_NOT_FOUND.equals(bytesToHex(buffer))) {
                                                System.out.println("Nexio MediaListener LIST_FIRST_ID_LIST ID not found!");
-                                       }else{
-                                               System.out.println("Nexio MediaListener unknown answer has arrived for LIST_FIRST_ID_LIST:  " + bytesToHex( buffer));
+                                       } else {
+                                               System.out.println("Nexio MediaListener unknown answer has arrived for LIST_FIRST_ID_LIST:  " + bytesToHex(buffer));
                                        }
-                               }catch(Exception exc){
+                               } catch (Exception exc) {
                                        exc.printStackTrace();
                                }
                        }
                        this.connection.disconnect();
-               }catch(Exception e){
+               } catch (Exception e) {
                        e.printStackTrace();
                }
        }
 
-       
-       private byte[] readBytes(int numberOfBytes) throws Exception{
-               try{
-                       byte[] ret = new byte[numberOfBytes];
-                       this.connection.read(ret, 0, numberOfBytes);
-                       return ret;
-               }catch(Exception e){
-                       //restartListener();
-                       throw e;
-               }
-       }
-       
-       private void writeBytes(byte[] toWrite) throws Exception{
-               try{
+       private void writeBytes(byte[] toWrite) throws Exception {
+               try {
                        //testcode calc checksum
-/*                     
-                       byte[] finalbytes = Arrays.copyOf(toWrite, toWrite.length + 1);
-                       long chksum = 0;
-                       for(int c=0; c<toWrite.length; c++){
-                               chksum += toWrite[c];
-                       }
-                       finalbytes[finalbytes.length-1] = (byte)(chksum | 1);
-*/                     
-                       this.connection.write(toWrite); //toWrite
+                       /*                      
+                                               byte[] finalbytes = Arrays.copyOf(toWrite, toWrite.length + 1);
+                                               long chksum = 0;
+                                               for(int c=0; c<toWrite.length; c++){
+                                                       chksum += toWrite[c];
+                                               }
+                                               finalbytes[finalbytes.length-1] = (byte)(chksum | 1);
+                       */
+                       this.connection.write(toWrite); //toWrite
                        this.connection.flush();
-               }catch(Exception e){
+               } catch (Exception e) {
                        //restartListener();
                        throw e;
                }
        }
-       
-       private void createNexioConnection() throws Exception{
-               this.connection = TCPConnection.getInstance(this.nexioHost, this.nexioPort);
-               System.out.println("Nexio MediaListener is connected to NEXIO " + this.nexioHost + " : " + this.nexioPort);
-       }
-       
-       
-       
-       public static void main(String[] args) throws UnknownHostException, IOException, ProtocolException, ClipNotFoundException {
-               ListMetabaseContents lmc = new ListMetabaseContents();
-               
-/*             
-               
-               
-               //MASK REQ                      RESP_NOT_NUM
-               //00 00 00 01           0x00                    IDs in Added List               BC=0x01, NN=0x00, DATA=none
-               //00 00 00 02           0x01                    IDs in Deleted List             BC=0x01, NN=0x01, DATA=none
-               byte[] CHANGE_NOTIFICATION_REQ = { (byte) 0xC4, (byte)0xA5, 0,0,0,0x03};        //+C4A5 + MASK
 
-               //10 01 response immediately
-               byte[] ACK = { (byte) 0x10, (byte)0x01};
-
-               //CF A6 BC NN DATA              NN=0 -> IDs are in added list, NN=1 -> IDs are in deleted list  
-               byte[] CHANGE_NOTIFICATION_RESP = { (byte) 0xCF, (byte)0xA6};
-
-               //List First ID List (C1 4C)    
-               byte[] LIST_FIRST_ID_LIST_ADDED =       { (byte) 0xC1, (byte)0x4C, (byte)0x02}; //2 added, 3 deleted
-               byte[] LIST_FIRST_ID_LIST_DELETED = { (byte) 0xC1, (byte)0x4C, (byte)0x03};     //2 added, 3 deleted
-
-               //List First ID List (C0 4D)    
-               byte[] LIST_NEXT_ID_LIST = { (byte) 0xC0, (byte)0x4D};
-               
-               
-               Connection connection = TCPConnection.getInstance(NEXIO_HOST, 557);
-//             connection.write(ID_LIST);
-//             connection.flush();
-
-       connection.write(CHANGE_NOTIFICATION_REQ);
-       connection.flush();
-       //ACK
-       byte[] buffer = new byte[2];
-       int c = connection.read(buffer, 0, 2);
-       
-       
-       while("1".equals("1")){
-       
-               //CHANGE_NOTIFICATION_RESP (blocking read)
-               buffer = new byte[4];
-               c = connection.read(buffer,0,4);                                //CFA6 BC NN -> 0=added, 1=deleted
-               System.out.println("change notification resp: " + bytesToHex(buffer));
-               
-               //ACK sending back
-               connection.write(ACK);
-               connection.flush();
-       
-               //LIST_FIRST_ID_LIST
-               
-               //0x01  Main ID Handle List     D8 4C ID
-               //0x02  ID Handles Added List   D8 4C ID
-               //0x03  ID Handles Deleted List D8 4C ID
-               //0x11  Main Extended ID List   DF 4C BC XID *
-               //0x12  Extended IDs Added List DF 4C BC XID *
-               //0x13  Extended IDs Deleted List       DF 4C BC XID *
-               //0x21  Main ID Handle/Extended ID List DF 4C BC ID XID *
-               //0x22  ID Handles/Extended IDs Added List      DF 4C BC ID XID *
-               //0x23  ID Handles/Extended IDs Deleted List    DF 4C BC ID XID *
-               
-               if(buffer[3] == 0){
-                       connection.write(LIST_FIRST_ID_LIST_ADDED);
-                       System.out.println("NN ADDED");
-               }else
-               if(buffer[3] == 1){
-                       connection.write(LIST_FIRST_ID_LIST_DELETED);
-                       System.out.println("NN DELETED");
-               }
-               connection.flush();
-       
-               //READ FIRST ID
-               buffer = new byte[2];
-               c = connection.read(buffer, 0, 2);
-               if("D84C".equals(bytesToHex(buffer))){
-                       System.out.println("reading first id...");
-                       
-                       //added or deleted
-                       buffer = new byte[8];
-                       c = connection.read(buffer, 0, 8);
-                       System.out.println("FIRST ID: " + new String(buffer));
-               
-                       //C0 4D List Next ID List
-                       connection.write(LIST_NEXT_ID_LIST);
-                       connection.flush();
-                       
-                       buffer = new byte[2];
-                       //D04D amikor elfogy
-                       for(connection.read(buffer, 0, 2);      bytesToHex(buffer).equals("D84D");      connection.read(buffer, 0, 2)){
-       
-                               buffer = new byte[8];
-                               c = connection.read(buffer, 0, 8);
-                               System.out.println("NEXT ID: " + new String(buffer));
-                       
-                               connection.write(LIST_NEXT_ID_LIST);
-                               connection.flush();
-                               
-                               buffer = new byte[2];
-                       }
-                       //System.out.println("LIST_NEXT_ID_LIST RESP: " + bytesToHex(buffer));
-               }else
-               if(bytesToHex(buffer).equals("D04C")){
-                                       System.out.println("No one found for first ID!");
-               }else{
-                       System.out.println("Error in list first id list response: " + bytesToHex( buffer));
-               }
-       }
-       
-       
-               //int i = connection.read();
-               connection.disconnect();
-*/             
-       }
-       
-       
-       
-       private static Id getNextId(Connection connection) throws IOException, ProtocolException{
-               byte[] buffer = new byte[8];
-               int c = connection.read(buffer, 0, 8);
-               if (c != 8){
-                       return null;    //throw getException_InvalidResponseLength(c, 8, 8);
-               }else{
-                       return new Id(new String(buffer));      
-               }
-       }
-       
-       
-       private static int getNOFIds(Connection connection) throws IOException, ProtocolException{
-               byte[] buffer = new byte[2];
-               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
-               int nofIds = ((buffer[0] << 8) & 0xFF00) | (buffer[1] & 0x00FF);                        //00000001 10010000
-               return nofIds;
-       }
-       
-       
-       public static String bytesToHex(byte[] bytes) {
-           char[] hexChars = new char[bytes.length * 2];
-           for ( int j = 0; j < bytes.length; j++ ) {
-               int v = bytes[j] & 0xFF;
-               hexChars[j * 2] = hexArray[v >>> 4];
-               hexChars[j * 2 + 1] = hexArray[v & 0x0F];
-           }
-           return new String(hexChars);
-       }
-       
-       
 }
index 562472af21d86cdb4e45ab3eea51ef26c6a93fa3..a0a82f9448d1e72c1c779bd63c8e40ca13248811 100644 (file)
@@ -23,6 +23,7 @@
                        <button label="Futtatás" onClick="@command('executeJob')" />\r
                        <button sclass="buttonboldfont" label="Leállítás" onClick="@command('shutdown')" autodisable="self" disabled="@load(jlm.shutdownDisabled)" />\r
                        <button sclass="buttonboldfont" label="Elindítás" onClick="@command('startup')" autodisable="self" disabled="@load(jlm.startupDisabled)" />\r
+                       <button sclass="buttonboldfont" label="NEXIO szinkronizálás" onClick="@command('restartNexio')" autodisable="self" />\r
                </div>\r
 \r
 \r
index e563a8c5272d0727ca17713e39f1699fa23df219..ae86a13f029620247aec949fe83b4e67fe6316ce 100644 (file)
@@ -92,8 +92,8 @@ div.z-row-content span {
                                                                <column hflex="min">\r
                                                                        <checkbox checked="@bind(vm.allSelected)" />\r
                                                                </column>\r
-                                                               <column label="ID" hflex="min" align="left" />\r
-                                                               <column label="Cím" align="left" />\r
+                                                               <column label="ID" sort="auto" hflex="min" align="left" />\r
+                                                               <column label="Cím" sort="auto" align="left" />\r
                                                                <column label="Fájlnév" hflex="min" align="left" />\r
                                                                <column label="Hossz" hflex="min" align="right" />\r
                                                        </columns>\r
index f796582faa570359605a796bcb6d36e067213a71..335d5606dde0dd679849a38a209b47e506798649 100644 (file)
@@ -1,4 +1,4 @@
-version=2.3.5\r
+version=2.3.6\r
 footer=2016 © Copyright User Rendszerház Kft.\r
 \r
 login_info=Információ\r
index 8ac2c049c2ada3246ecfa345240e3dbd7d053bfc..cfa6d09392995681f7b44cb03f2a6263d93c78de 100644 (file)
@@ -5,11 +5,16 @@ import java.util.Map;
 \r
 import org.apache.logging.log4j.LogManager;\r
 import org.apache.logging.log4j.Logger;\r
+import org.osgi.framework.BundleContext;\r
+import org.osgi.framework.FrameworkUtil;\r
+import org.osgi.framework.ServiceReference;\r
 import org.zkoss.bind.annotation.BindingParam;\r
 import org.zkoss.bind.annotation.Command;\r
 import org.zkoss.bind.annotation.Init;\r
 import org.zkoss.bind.annotation.NotifyChange;\r
 import org.zkoss.zk.ui.Executions;\r
+import org.zkoss.zk.ui.event.Event;\r
+import org.zkoss.zk.ui.event.EventListener;\r
 import org.zkoss.zul.ListModelList;\r
 import org.zkoss.zul.Messagebox;\r
 import org.zkoss.zul.Window;\r
@@ -17,6 +22,7 @@ import org.zkoss.zul.Window;
 import com.ibm.nosql.json.api.BasicDBObject;\r
 \r
 import user.commons.ListUtils;\r
+import user.commons.nexio.api.ClipEventListener;\r
 import user.jobengine.db.ItemManagerData.SignalType;\r
 import user.jobengine.server.IJobChangedListener;\r
 import user.jobengine.server.IJobEngine;\r
@@ -87,8 +93,8 @@ public class JobListModel extends AsyncBaseModel implements IJobChangedListener
 \r
                        initializeList();\r
 \r
-               } catch (Exception exc) {\r
-                       logger.error("", exc);\r
+               } catch (Exception e) {\r
+                       logger.catching(e);\r
                        setStartupDisabled(true);\r
                        setShutdownDisabled(true);\r
                }\r
@@ -167,6 +173,28 @@ public class JobListModel extends AsyncBaseModel implements IJobChangedListener
                t.start();\r
        }\r
 \r
+       @Command\r
+       public void restartNexio() {\r
+               EventListener<Event> confirmedEvent = evt -> {\r
+                       if (evt.getName().equals("onCancel"))\r
+                               return;\r
+                       try {\r
+                               BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();\r
+                               if (bundleContext == null)\r
+                                       return;\r
+                               ServiceReference<ClipEventListener> reference = bundleContext.getServiceReference(ClipEventListener.class);\r
+                               ClipEventListener listener = bundleContext.getService(reference);\r
+                               listener.restart();\r
+                       } catch (Exception e) {\r
+                               Messagebox.show(e.getMessage());\r
+                       }\r
+               };\r
+\r
+               Messagebox.show("Biztosan újra akarod szinkronizálni a NEXIO adatokat?", "Kérdés", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION,\r
+                               confirmedEvent);\r
+\r
+       }\r
+\r
        public void setJobList(ListModelList<IJobRuntime> jobList) {\r
                this.jobList = jobList;\r
        }\r
index 9bb6d9eafdf250522e0c4b50f15a87e0261afb2a..6c296a81c2610fd8c5b4864e87754d3b2081aa19 100644 (file)
@@ -19,10 +19,14 @@ import org.zkoss.bind.annotation.ContextParam;
 import org.zkoss.bind.annotation.ContextType;\r
 import org.zkoss.bind.annotation.NotifyChange;\r
 import org.zkoss.zk.ui.Component;\r
+import org.zkoss.zk.ui.event.EventListener;\r
 import org.zkoss.zk.ui.event.MouseEvent;\r
+import org.zkoss.zk.ui.event.SortEvent;\r
 import org.zkoss.zk.ui.select.Selectors;\r
 import org.zkoss.zk.ui.select.annotation.Wire;\r
 import org.zkoss.zul.Checkbox;\r
+import org.zkoss.zul.Column;\r
+import org.zkoss.zul.Columns;\r
 import org.zkoss.zul.Detail;\r
 import org.zkoss.zul.Grid;\r
 import org.zkoss.zul.Hlayout;\r
@@ -136,6 +140,27 @@ public class SearchModel extends AsyncBaseModel {
        public void afterCompose(@ContextParam(ContextType.VIEW) Component view) {\r
                Selectors.wireComponents(view, this, false);\r
                Selectors.wireEventListeners(view, this);\r
+               itemsGrid.getPagingChild().setAutohide(false);\r
+               Columns columns = itemsGrid.getColumns();\r
+               for (Component child : columns.getChildren()) {\r
+                       Column column = (Column) child;\r
+                       column.addEventListener("onSort", new EventListener<SortEvent>() {\r
+                               @Override\r
+                               public void onEvent(SortEvent evt) throws Exception {\r
+                                       for (Component child : columns.getChildren()) {\r
+                                               Column column = (Column) child;\r
+                                               column.setSortDirection("natural");\r
+                                       }\r
+                                       Column column = (Column) evt.getTarget();\r
+                                       if (evt.isAscending())\r
+                                               column.setSortDirection("ascending");\r
+                                       else\r
+                                               column.setSortDirection("descending");\r
+                                       logger.info("{} {}", column.getLabel(), evt.isAscending());\r
+                                       evt.stopPropagation();\r
+                               }\r
+                       });\r
+               }\r
        }\r
 \r
        @Command\r
index 2737ccd1e0bebbdcf9debe634d814628ac6af735..97e429fde496a7d1fab903e447c55ba5946775f3 100644 (file)
@@ -33,6 +33,7 @@ Import-Package: com.fasterxml.jackson.annotation;version="2.4.5",
  org.osgi.framework;version="1.8.0",
  user.commons,
  user.commons.nexio,
+ user.commons.nexio.api,
  user.commons.octopus,
  user.jobengine.db,
  user.jobengine.server
index 3cde24ec94e0ce03c605abcc93646324a43214bf..3ea70d0e35c7da768b2af961bbb053fc59548e04 100644 (file)
@@ -10,11 +10,14 @@ import org.eclipse.jetty.util.ConcurrentHashSet;
 import org.eclipse.jetty.websocket.api.Session;
 import org.eclipse.jetty.websocket.servlet.WebSocketServlet;
 import org.eclipse.jetty.websocket.servlet.WebSocketServletFactory;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
 
 import com.ibm.nosql.json.api.BasicDBObject;
 
 import user.commons.nexio.INexioChangeListener;
 import user.commons.nexio.NexioDispatcher;
+import user.commons.nexio.api.ClipEventListener;
 
 @SuppressWarnings("serial")
 public class NexioWSServlet extends WebSocketServlet implements INexioChangeListener {
@@ -29,27 +32,18 @@ public class NexioWSServlet extends WebSocketServlet implements INexioChangeList
        }
 
        private Set<Session> sessions = new ConcurrentHashSet<>();
-
-       //private NexioAPIServletMessagePool messagePool;
        private NexioDispatcher dispatcher = null;
 
        public NexioWSServlet() {
                logger.info("Created");
-               //              messagePool = new NexioAPIServletMessagePool(3, sessions);
                instance = this;
                dispatcher = new NexioDispatcher();
                dispatcher.setNexioChangeListener(this);
                dispatcher.startup();
                logger.info("Initialized");
-               /*
-                               BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
-                               if (bundleContext != null) {
-                                       ServiceRegistration<INexioChangeListener> registerService = bundleContext
-                                                       .registerService(INexioChangeListener.class, this, null);
-               
-                                       logger.info("{} successfully registered", INexioChangeListener.class.getSimpleName());
-                               }
-               */
+               BundleContext bundleContext = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
+               if (bundleContext != null)
+                       bundleContext.registerService(ClipEventListener.class, dispatcher, null);
        }
 
        public void addSession(Session session) {