\r
public class NexioAPI implements INexioAPI {\r
private static final Logger logger = LogManager.getLogger();\r
+ private static final String MODIFIEDTIMESTAMP = "modifiedtimestamp";\r
\r
@Override\r
public List<DBObject> getItems(Date modified, boolean itemsWithAgency) {\r
try {\r
db = NoSQLUtils.getDB();\r
DBCollection collection = db.getCollection(NexioDataMiner.CLIP_COLLECTION_NAME);\r
- DBCursor find = collection.find().sort(new BasicDBObject("modified", new BasicDBList(-1, "$date")));\r
+ DBCursor find = collection.find().sort(new BasicDBObject(MODIFIEDTIMESTAMP, new BasicDBList(-1, "$date")));\r
if (find.hasNext())\r
result = find.toArray();\r
} catch (Exception e) {\r
try {\r
jsClip.put(ID, clip.getId().get()); //Unique internal ID\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(LONGNAMEID, clip.getXid().get()); //Extended ID (Filename)\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(DURATION, clip.getDuration());\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(MODIFIEDTIMESTAMP, clip.getModifiedTimestamp().getTime());\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(VIDEO_FORMAT, clip.getVideoFormat());\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(VIDEO_BITRATE, clip.getVideoBitrate());\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(FILESIZE, clip.getFileSize());\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
}\r
try {\r
jsClip.put(EXTAGENCY, new String(clip.getExtendedField(GetExtendedFieldCommand.FN_AGENCY)));\r
} catch (Exception e) {\r
- System.out.println(e);\r
+ // System.out.println(e);\r
+ }\r
+ try {\r
+ jsClip.put(RECORDDATE, clip.getRecordDateTimestamp().getTime());\r
+ } catch (Exception e) {\r
+ // System.out.println(e);\r
+ }\r
+ try {\r
+ jsClip.put(DURATION, clip.getDuration());\r
+ } catch (Exception e) {\r
+ // System.out.println(e);\r
}\r
//jsClip.put(RECORDDATE, new DateTime(rs.getString(i++)).toDate());\r
//jsClip.put(EXTAGENCY, rs.getString(i++));\r
package user.commons.nexio.api;
-import user.commons.nexio.server.protocol.*;
import java.io.IOException;
import java.util.Calendar;
+import user.commons.nexio.server.protocol.Id;
+import user.commons.nexio.server.protocol.ProtocolException;
+import user.commons.nexio.server.protocol.Xid;
+
public interface Clip {
public int getDuration() throws ClipNotFoundException, IOException, ProtocolException;
-
- public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException;
-
- public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException;
+
+ public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException;
+
+ public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException;
public Id getId();
public Calendar getModifiedTimestamp() throws ClipNotFoundException, IOException, ProtocolException;
+ Calendar getRecordDateTimestamp() throws ClipNotFoundException, IOException, ProtocolException;
+
+ public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException;
+
+ public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException;
+
public Xid getXid() throws ClipNotFoundException, IOException, ProtocolException;
-
- public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException;
-
- public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException;
-
+
}
package user.commons.nexio.api;
-import user.commons.nexio.server.protocol.*;
import java.io.IOException;
import java.util.Calendar;
+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;
+
class ClipImpl implements Clip {
private static final String PROTOCOL = "protocol";
metadata = protocol.executeGetIDMetadata(id);
checkClipExists(metadata);
}
- return metadata[16] + (metadata[17] << 8) + (metadata[18] << 16)
- + (metadata[19] << 24);
+ return metadata[16] + (metadata[17] << 8) + (metadata[18] << 16) + (metadata[19] << 24);
}
- /**
- @return
- 0x00 Not supported
- 0x01 Not supported
- 0x02 MPEG2 4:2:0
- 0x03 MPEG2 4:2:2
- 0x04 DVCAM version of DV25
- 0x05 DVCPRO version of DV25
- 0x06 DV50, DVCPRO HD, or DNxHD
- 0x07 Uncompressed KRGB 8 bits
- 0x08 Uncompressed K 16 bits
- 0x09 IMX (MPEG 4:2:2), CBG (constrained bytes per GOP)
- 0x0A H.264 4:2:0
- 0x0B H.264 4:2:2
- 0x0C H.264 4:2:0 CBG (e.g. AVC-Intra class 50)
- 0x0D H.264 4:2:2 CBG (e.g. AVC-Intra class 100)
- 0x0E Reserved
- 0x0F Audio-only (no video)
- */
@Override
- public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException{
- if (metadata == null) {
- metadata = protocol.executeGetIDMetadata(id);
- checkClipExists(metadata);
+ public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException {
+ return protocol.executeGetExtendedFieldCommand(id, fieldNumber);
+ }
+
+ @Override
+ public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException {
+ if (fileSize == -1) {
+ fileSize = protocol.executeGetIDFileSizeCommand(id);
+ checkClipExists(fileSize > -1 ? new Long(fileSize) : null);
}
- return metadata[8];
+ return fileSize;
}
+ @Override
+ public Id getId() {
+ return id;
+ }
+
+ @Override
+ public Calendar getModifiedTimestamp() throws ClipNotFoundException, IOException, ProtocolException {
+ if (timestamp == null) {
+ timestamp = protocol.executeGetExtendedFieldGetModifiedTimestamp(id);
+ checkClipExists(timestamp);
+ }
+ return timestamp;
+ }
+ @Override
+ public Calendar getRecordDateTimestamp() throws ClipNotFoundException, IOException, ProtocolException {
+ if (timestamp == null) {
+ timestamp = protocol.executeGetExtendedFieldGetModifiedTimestamp(id);
+ checkClipExists(timestamp);
+ }
+ return timestamp;
+ }
@Override
- public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException{
+ public int getVideoBitrate() throws ClipNotFoundException, IOException, ProtocolException {
int ret = 0;
if (metadata == null) {
metadata = protocol.executeGetIDMetadata(id);
checkClipExists(metadata);
}
- //Exact report of the compressed bit rate of the video portion of the clip.
- //The 2 bytes are returned LSB first. This information replaces information provided
+ //Exact report of the compressed bit rate of the video portion of the clip.
+ //The 2 bytes are returned LSB first. This information replaces information provided
//in Data #11 as of the NEXIO 6.0 Software Release
- ret = metadata[20] + (metadata[21] << 8);
- if(ret == 0){
+ ret = metadata[20] + (metadata[21] << 8);
+ if (ret == 0) {
//Use the information in this field only if the Exact Video Bit Rate = 0 (Data #20-21).
//It reports the compressed bit rate of the video portion of the clip.
//See note below for interpreting values >50 Mb/s.
return ret;
}
-
-
-
- @Override
- public Id getId() {
- return id;
- }
-
+ /**
+ * @return 0x00 Not supported 0x01 Not supported 0x02 MPEG2 4:2:0 0x03 MPEG2 4:2:2 0x04 DVCAM version of DV25 0x05 DVCPRO version of DV25 0x06 DV50, DVCPRO
+ * HD, or DNxHD 0x07 Uncompressed KRGB 8 bits 0x08 Uncompressed K 16 bits 0x09 IMX (MPEG 4:2:2), CBG (constrained bytes per GOP) 0x0A H.264 4:2:0
+ * 0x0B H.264 4:2:2 0x0C H.264 4:2:0 CBG (e.g. AVC-Intra class 50) 0x0D H.264 4:2:2 CBG (e.g. AVC-Intra class 100) 0x0E Reserved 0x0F Audio-only (no
+ * video)
+ */
@Override
- public Calendar getModifiedTimestamp() throws ClipNotFoundException,
- IOException, ProtocolException {
- if (timestamp == null) {
- timestamp = protocol
- .executeGetExtendedFieldGetModifiedTimestamp(id);
- checkClipExists(timestamp);
+ public int getVideoFormat() throws ClipNotFoundException, IOException, ProtocolException {
+ if (metadata == null) {
+ metadata = protocol.executeGetIDMetadata(id);
+ checkClipExists(metadata);
}
- return timestamp;
+ return metadata[8];
}
@Override
- public Xid getXid() throws ClipNotFoundException, IOException,
- ProtocolException {
+ public Xid getXid() throws ClipNotFoundException, IOException, ProtocolException {
if (xid == null) {
xid = protocol.executeGetExtendedIDFromIDHandle(id);
checkClipExists(xid);
}
return xid;
}
-
- @Override
- public long getFileSize() throws ClipNotFoundException, IOException, ProtocolException {
- if (fileSize == -1) {
- fileSize = protocol.executeGetIDFileSizeCommand(id);
- checkClipExists(fileSize > -1 ? new Long(fileSize) : null);
- }
- return fileSize;
- }
- @Override
- public byte[] getExtendedField(byte[] fieldNumber) throws IOException, ProtocolException{
- return protocol.executeGetExtendedFieldCommand(id, fieldNumber);
- }
-
}
--- /dev/null
+package user.commons.nexio.server.protocol;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.Calendar;
+
+public class GetExtendedFieldGetRecordDateTimestampCommand extends Command {
+
+ private final static byte[] GET_EXTENDED_FIELD = { (byte) 0xc9, (byte) 0xc3 };
+ private final static byte[] EXTENDED_FIELD_NUMBER = { (byte) 0 };
+
+ private byte[] buffer;
+ private byte filetime[];
+
+ public GetExtendedFieldGetRecordDateTimestampCommand(Connection connection) {
+ super(connection);
+ }
+
+ private Calendar convertFromFILETIME(byte[] filetime) {
+ Calendar result = Calendar.getInstance();
+
+ ByteBuffer b = ByteBuffer.wrap(filetime);
+ b.order(ByteOrder.LITTLE_ENDIAN);
+ int lo = b.asIntBuffer().get(0);
+ int hi = b.asIntBuffer().get(1);
+
+ long wFILETIME = ((long) hi << 32) + lo;
+
+ final long EPOCH_DIFF = 11644473600000L;
+ final long ms_since_16010101 = wFILETIME / (10000);
+ final long ms_since_19700101 = ms_since_16010101 - EPOCH_DIFF;
+
+ result.setTimeInMillis(ms_since_19700101);
+
+ return result;
+ }
+
+ public Calendar execute(Id id) throws IOException, ProtocolException {
+
+ Calendar ret = null;
+
+ connection.write(GET_EXTENDED_FIELD);
+ connection.write(id.get().getBytes());
+ connection.write(EXTENDED_FIELD_NUMBER);
+ connection.flush();
+
+ buffer = new byte[2];
+ int c = connection.read(buffer, 0, 2);
+ if (c < 2) {
+ throw getException_InvalidResponseLength(c, 2, 2);
+ }
+
+ // Not found
+ if (buffer[0] == (byte) 0xd0 && buffer[1] == (byte) 0xc3) {
+ throw new ProtocolException("ID handle is not found!");
+ } else
+ // 1. Found
+ if (buffer[0] == (byte) 0xdf && buffer[1] == (byte) 0xc3) {
+
+ // 2. read NOF BYTES
+ buffer = new byte[1];
+ c = connection.read(buffer, 0, 1);
+
+ int toRead = buffer[0];
+ if (toRead != 8) {
+ throw new ProtocolException("Invalid ModifiedTimeStamp's data length: " + toRead);
+ } else {
+ filetime = new byte[8];
+ c = connection.read(filetime, 0, 8);
+ if (c != 8) {
+ throw getException_InvalidResponseLength(c, 8, 8);
+ }
+ ret = convertFromFILETIME(filetime);
+ }
+ }
+ return ret;
+ }
+}
import java.io.IOException;
import java.util.Calendar;
-import java.util.List;
public interface NexioServerProtocol {
+ public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException;
+
public Calendar executeGetExtendedFieldGetModifiedTimestamp(Id id) throws IOException, ProtocolException;
+ public Calendar executeGetExtendedFieldGetRecordDateTimestamp(Id id) throws IOException, ProtocolException;
+
public Xid executeGetExtendedIDFromIDHandle(Id id) throws IOException, ProtocolException;
+ public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException;
+
public Id executeGetIDHandleFromExtendedID(Xid xid) throws IOException, ProtocolException;
public byte[] executeGetIDMetadata(Id id) throws IOException, ProtocolException;
public Id executeListNextIDHandle() throws IOException, ProtocolException;
- public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException;
-
public byte executePortStatusCommand() throws IOException, ProtocolException;
-
- public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException;
-
+
public Connection getConnection();
-
+
}
import java.io.IOException;
import java.util.Calendar;
-import java.util.List;
public class NexioServerProtocolImpl implements NexioServerProtocol {
private GetIDMetadataCommand getIDMetadataCommand = null;
private GetIDHandleFromExtendedIDCommand getIDHandleFromExtendedIDCommand = null;
private GetExtendedFieldGetModifiedTimestampCommand getExtendedFieldGetModifiedTimestampCommand = null;
+ private GetExtendedFieldGetRecordDateTimestampCommand getExtendedFieldGetRecordDateTimestampCommand = null;
private ListFirstIDHandleCommand listFirstIDHandleCommand = null;
private ListNextIDHandleCommand listNextIDHandleCommand = null;
private GetIDFileSizeCommand getIDFileSizeCommand = null;
private PortStatusCommand portStatusCommand = null;
private GetExtendedFieldCommand getExtendedFieldCommand = null;
-
+
private Connection connection = null;
-
+
public NexioServerProtocolImpl(Connection _connection) {
this.connection = _connection;
getExtendedIDFromIDHandleCommand = new GetExtendedIDFromIDHandleCommand(connection);
getIDMetadataCommand = new GetIDMetadataCommand(connection);
getIDHandleFromExtendedIDCommand = new GetIDHandleFromExtendedIDCommand(connection);
getExtendedFieldGetModifiedTimestampCommand = new GetExtendedFieldGetModifiedTimestampCommand(connection);
+ getExtendedFieldGetRecordDateTimestampCommand = new GetExtendedFieldGetRecordDateTimestampCommand(connection);
listFirstIDHandleCommand = new ListFirstIDHandleCommand(connection);
listNextIDHandleCommand = new ListNextIDHandleCommand(connection);
getIDFileSizeCommand = new GetIDFileSizeCommand(connection);
portStatusCommand = new PortStatusCommand(connection);
- getExtendedFieldCommand = new GetExtendedFieldCommand(connection);
+ getExtendedFieldCommand = new GetExtendedFieldCommand(connection);
+ }
+
+ @Override
+ public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException {
+ return getExtendedFieldCommand.execute(id, fieldNumber);
}
@Override
return getExtendedFieldGetModifiedTimestampCommand.execute(id);
}
+ @Override
+ public Calendar executeGetExtendedFieldGetRecordDateTimestamp(Id id) throws IOException, ProtocolException {
+ return getExtendedFieldGetRecordDateTimestampCommand.execute(id);
+ }
+
@Override
public Xid executeGetExtendedIDFromIDHandle(Id id) throws IOException, ProtocolException {
return getExtendedIDFromIDHandleCommand.execute(id);
}
+ @Override
+ public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException {
+ return getIDFileSizeCommand.execute(id);
+ }
+
@Override
public Id executeGetIDHandleFromExtendedID(Xid xid) throws IOException, ProtocolException {
return getIDHandleFromExtendedIDCommand.execute(xid);
}
@Override
- public long executeGetIDFileSizeCommand(Id id) throws IOException, ProtocolException {
- return getIDFileSizeCommand.execute(id);
- }
-
- @Override
- public byte executePortStatusCommand() throws IOException, ProtocolException{
- return portStatusCommand.execute();
+ public byte executePortStatusCommand() throws IOException, ProtocolException {
+ return portStatusCommand.execute();
}
@Override
- public byte[] executeGetExtendedFieldCommand(Id id, byte[] fieldNumber) throws IOException, ProtocolException{
- return getExtendedFieldCommand.execute(id, fieldNumber);
- }
-
-
- @Override
- public Connection getConnection(){;
+ public Connection getConnection() {
+ ;
return this.connection;
}
-
}
package user.jobengine.osgi.ws.nexio;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Set;
import org.apache.logging.log4j.LogManager;
this.dispatcher = new NexioClipEventDispatcher();
this.dispatcher.setNexioChangeListener(this);
logger.info("NexioWSServlet has been 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());
}
*/
}
private void processMessage(BasicDBObject message) {
+ List<Session> deadSessions = null;
for (Session session : sessions) {
try {
NexioWSSocket.asyncSendResponse(session, message);
} catch (Exception e) {
- // TODO remove closed
logger.error(e);
+ if (deadSessions == null)
+ deadSessions = new ArrayList<>();
+ deadSessions.add(session);
}
}
+
+ if (deadSessions != null)
+ sessions.removeAll(deadSessions);
}
public void removeSession(Session session) {