Issue #2228 use TMemoryInputTransport for slight efficiency improvement

Change-Id: I280dacdd48f5e092b312a80916db6202a1138ebf

Former-commit-id: 963119e0f3 [formerly d4590cbf5e] [formerly 963119e0f3 [formerly d4590cbf5e] [formerly 842f15ae12 [formerly 3f3afa1fe36da04ce47b9af1e8bd34746b75e68f]]]
Former-commit-id: 842f15ae12
Former-commit-id: 584a17828a [formerly 7d17d965a3]
Former-commit-id: 0abec57d0d
This commit is contained in:
Nate Jensen 2013-08-06 09:52:02 -05:00
parent 18dad40473
commit 6585abee8e
15 changed files with 140 additions and 158 deletions

View file

@ -20,7 +20,6 @@
package com.raytheon.uf.viz.core.comm; package com.raytheon.uf.viz.core.comm;
import java.io.ByteArrayInputStream;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -35,8 +34,8 @@ import com.raytheon.uf.common.message.response.ResponseMessageCatalog;
import com.raytheon.uf.common.message.response.ResponseMessageError; import com.raytheon.uf.common.message.response.ResponseMessageError;
import com.raytheon.uf.common.message.response.ResponseMessageGeneric; import com.raytheon.uf.common.message.response.ResponseMessageGeneric;
import com.raytheon.uf.common.serialization.DynamicSerializationManager; import com.raytheon.uf.common.serialization.DynamicSerializationManager;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType; import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType;
import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.exception.VizException;
import com.raytheon.uf.viz.core.exception.VizServerSideException; import com.raytheon.uf.viz.core.exception.VizServerSideException;
@ -51,6 +50,7 @@ import com.raytheon.uf.viz.core.exception.VizServerSideException;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Sep 11, 2006 chammack Initial Creation. * Sep 11, 2006 chammack Initial Creation.
* 09May2007 TO7 njensen Fixed XML responses. * 09May2007 TO7 njensen Fixed XML responses.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -84,8 +84,7 @@ public class MessageMarshaller {
DynamicSerializationManager dsm = DynamicSerializationManager DynamicSerializationManager dsm = DynamicSerializationManager
.getManager(SerializationType.Thrift); .getManager(SerializationType.Thrift);
Object rawMsg = dsm.deserialize(message);
Object rawMsg = dsm.deserialize(new ByteArrayInputStream(message));
if (!(rawMsg instanceof Message)) if (!(rawMsg instanceof Message))
throw new VizException( throw new VizException(

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.viz.core.notification; package com.raytheon.uf.viz.core.notification;
import java.io.ByteArrayInputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.List; import java.util.List;
@ -44,6 +43,7 @@ import com.raytheon.uf.viz.core.exception.VizException;
* Sep 2, 2008 1448 chammack Initial creation * Sep 2, 2008 1448 chammack Initial creation
* Oct 4, 2010 7193 cjeanbap Added a new method, isNotExpired(). * Oct 4, 2010 7193 cjeanbap Added a new method, isNotExpired().
* Feb 1, 2011 7193 cjeanbap Added a new method, getPublishedTime(). * Feb 1, 2011 7193 cjeanbap Added a new method, getPublishedTime().
* Aug 6, 2013 2228 njensen Use deserialize(byte[])
* </pre> * </pre>
* *
* @author chammack * @author chammack
@ -98,12 +98,10 @@ public class NotificationMessage {
throw new NotificationException( throw new NotificationException(
"Message payload terminated early. Expected: " "Message payload terminated early. Expected: "
+ length + ". Got: " + readLength); + length + ". Got: " + readLength);
ByteArrayInputStream bais = new ByteArrayInputStream(
data);
this.unmarshalledObject = DynamicSerializationManager this.unmarshalledObject = DynamicSerializationManager
.getManager(SerializationType.Thrift) .getManager(SerializationType.Thrift)
.deserialize(bais); .deserialize(data);
} else if (this.jmsMessage instanceof TextMessage) { } else if (this.jmsMessage instanceof TextMessage) {
TextMessage textMessage = (TextMessage) this.jmsMessage; TextMessage textMessage = (TextMessage) this.jmsMessage;
this.unmarshalledObject = SerializationUtil this.unmarshalledObject = SerializationUtil
@ -180,7 +178,8 @@ public class NotificationMessage {
public boolean isNotExpired() throws NotificationException { public boolean isNotExpired() throws NotificationException {
try { try {
long currentTime = System.currentTimeMillis(); long currentTime = System.currentTimeMillis();
return (currentTime < this.jmsMessage.getJMSExpiration() ? true : false); return (currentTime < this.jmsMessage.getJMSExpiration() ? true
: false);
} catch (JMSException e) { } catch (JMSException e) {
throw new NotificationException( throw new NotificationException(
"Error retrieving source information", e); "Error retrieving source information", e);
@ -188,8 +187,8 @@ public class NotificationMessage {
} }
/** /**
* Returns the time as a long when the message was handled off to the provider to * Returns the time as a long when the message was handled off to the
* be sent. * provider to be sent.
* *
* @return long, the time as in milliseconds. * @return long, the time as in milliseconds.
* @throws NotificationException * @throws NotificationException

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.common.dataplugin.cwat; package com.raytheon.uf.common.dataplugin.cwat;
import java.io.ByteArrayInputStream;
import java.util.HashMap; import java.util.HashMap;
import javax.persistence.Access; import javax.persistence.Access;
@ -74,11 +73,12 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 06/03/09 2037 D. Hladky Initial release * 06/03/09 2037 D. Hladky Initial release
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime * Apr 04, 2013 1846 bkowal Added an index on refTime and forecastTime
* 04/08/13 1293 bkowal Removed references to hdffileid. * 04/08/13 1293 bkowal Removed references to hdffileid.
* Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation. * Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation.
* May 07, 2013 1869 bsteffen Remove dataURI column from * May 07, 2013 1869 bsteffen Remove dataURI column from
* PluginDataObject. * PluginDataObject.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -92,17 +92,13 @@ import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement;
* Both refTime and forecastTime are included in the refTimeIndex since * Both refTime and forecastTime are included in the refTimeIndex since
* forecastTime is unlikely to be used. * forecastTime is unlikely to be used.
*/ */
@org.hibernate.annotations.Table( @org.hibernate.annotations.Table(appliesTo = "cwat", indexes = { @Index(name = "cwat_refTimeIndex", columnNames = {
appliesTo = "cwat", "refTime", "forecastTime" }) })
indexes = {
@Index(name = "cwat_refTimeIndex", columnNames = { "refTime", "forecastTime" } )
}
)
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize @DynamicSerialize
public class CWATRecord extends PersistablePluginDataObject public class CWATRecord extends PersistablePluginDataObject implements
implements IPersistable, ISpatialEnabled { IPersistable, ISpatialEnabled {
private static final long serialVersionUID = 76774564365671L; private static final long serialVersionUID = 76774564365671L;
@ -476,10 +472,9 @@ public class CWATRecord extends PersistablePluginDataObject
if (getThreats().size() < 1) { if (getThreats().size() < 1) {
ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve( ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve(
getDataURI(), THREATS, Request.ALL); getDataURI(), THREATS, Request.ALL);
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setThreats((HashMap<ThreatLocation, ThreatReport>) o); setThreats((HashMap<ThreatLocation, ThreatReport>) o);
} }
} catch (Throwable e) { } catch (Throwable e) {

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.common.dataplugin.preciprate; package com.raytheon.uf.common.dataplugin.preciprate;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Map; import java.util.Map;
@ -76,11 +75,12 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 01/25/10 3796 D. Hladky Initial release * 01/25/10 3796 D. Hladky Initial release
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime * Apr 04, 2013 1846 bkowal Added an index on refTime and forecastTime
* 04/08/13 1293 bkowal Removed references to hdffileid. * 04/08/13 1293 bkowal Removed references to hdffileid.
* Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation. * Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation.
* May 07, 2013 1869 bsteffen Remove dataURI column from * May 07, 2013 1869 bsteffen Remove dataURI column from
* PluginDataObject. * PluginDataObject.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -94,17 +94,13 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* Both refTime and forecastTime are included in the refTimeIndex since * Both refTime and forecastTime are included in the refTimeIndex since
* forecastTime is unlikely to be used. * forecastTime is unlikely to be used.
*/ */
@org.hibernate.annotations.Table( @org.hibernate.annotations.Table(appliesTo = "preciprate", indexes = { @Index(name = "preciprate_refTimeIndex", columnNames = {
appliesTo = "preciprate", "refTime", "forecastTime" }) })
indexes = {
@Index(name = "preciprate_refTimeIndex", columnNames = { "refTime", "forecastTime" } )
}
)
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize @DynamicSerialize
public class PrecipRateRecord extends PersistablePluginDataObject public class PrecipRateRecord extends PersistablePluginDataObject implements
implements IMonitorProcessing { IMonitorProcessing {
private static final transient IUFStatusHandler statusHandler = UFStatus private static final transient IUFStatusHandler statusHandler = UFStatus
.getHandler(PrecipRateRecord.class); .getHandler(PrecipRateRecord.class);
@ -342,10 +338,9 @@ public class PrecipRateRecord extends PersistablePluginDataObject
} else if (dataRec[i].getName().equals("DHRMap")) { } else if (dataRec[i].getName().equals("DHRMap")) {
try { try {
ByteDataRecord byteData = (ByteDataRecord) dataRec[i]; ByteDataRecord byteData = (ByteDataRecord) dataRec[i];
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setDhrMap((Map<DHRValues, Double>) o); setDhrMap((Map<DHRValues, Double>) o);
} catch (SerializationException e) { } catch (SerializationException e) {
e.printStackTrace(); e.printStackTrace();

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.common.dataplugin.radar.util; package com.raytheon.uf.common.dataplugin.radar.util;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -52,9 +51,10 @@ import com.raytheon.uf.common.serialization.SerializationException;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Feb 21, 2011 mschenke Initial creation * Feb 21, 2011 mschenke Initial creation
* Mar 18, 2013 1804 bsteffen Remove AlphanumericValues from radar * Mar 18, 2013 1804 bsteffen Remove AlphanumericValues from radar
* HDF5. * HDF5.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -97,66 +97,58 @@ public class RadarDataRetriever {
} else if (record.getName().equals( } else if (record.getName().equals(
RadarStoredData.GRAPHIC_BLOCK_ID)) { RadarStoredData.GRAPHIC_BLOCK_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setGraphicBlock((GraphicBlock) o); radarData.setGraphicBlock((GraphicBlock) o);
} else if (record.getName() } else if (record.getName()
.equals(RadarStoredData.SYM_BLOCK_ID)) { .equals(RadarStoredData.SYM_BLOCK_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setSymbologyBlock((SymbologyBlock) o); radarData.setSymbologyBlock((SymbologyBlock) o);
} else if (record.getName().equals(RadarStoredData.SYM_DATA_ID)) { } else if (record.getName().equals(RadarStoredData.SYM_DATA_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData radarData
.setSymbologyData((HashMap<RadarDataKey, RadarDataPoint>) o); .setSymbologyData((HashMap<RadarDataKey, RadarDataPoint>) o);
} else if (record.getName().equals( } else if (record.getName().equals(
RadarStoredData.PRODUCT_VALS_ID)) { RadarStoredData.PRODUCT_VALS_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData radarData
.setProductVals((HashMap<RadarConstants.MapValues, Map<String, Map<RadarConstants.MapValues, String>>>) o); .setProductVals((HashMap<RadarConstants.MapValues, Map<String, Map<RadarConstants.MapValues, String>>>) o);
} else if (record.getName().equals( } else if (record.getName().equals(
RadarStoredData.RECORD_VALS_ID)) { RadarStoredData.RECORD_VALS_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData radarData
.setMapRecordVals((HashMap<RadarConstants.MapValues, Map<RadarConstants.MapValues, String>>) o); .setMapRecordVals((HashMap<RadarConstants.MapValues, Map<RadarConstants.MapValues, String>>) o);
} else if (record.getName().equals(RadarStoredData.GSM_ID)) { } else if (record.getName().equals(RadarStoredData.GSM_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setGsmMessage((GSMMessage) o); radarData.setGsmMessage((GSMMessage) o);
} else if (record.getName() } else if (record.getName()
.equals(RadarStoredData.STORM_IDS_ID)) { .equals(RadarStoredData.STORM_IDS_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setStormIDs((Map<String, RadarDataKey>) o); radarData.setStormIDs((Map<String, RadarDataKey>) o);
} else if (record.getName().equals(RadarStoredData.AAP_ID)) { } else if (record.getName().equals(RadarStoredData.AAP_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setAapMessage((AlertAdaptationParameters) o); radarData.setAapMessage((AlertAdaptationParameters) o);
} else if (record.getName().equals( } else if (record.getName().equals(
RadarStoredData.THRESHOLDS_ID)) { RadarStoredData.THRESHOLDS_ID)) {
@ -170,10 +162,9 @@ public class RadarDataRetriever {
} else if (record.getName().equals( } else if (record.getName().equals(
RadarStoredData.ALERT_MESSAGE_ID)) { RadarStoredData.ALERT_MESSAGE_ID)) {
ByteDataRecord byteData = (ByteDataRecord) record; ByteDataRecord byteData = (ByteDataRecord) record;
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
radarData.setAlertMessage((AlertMessage) o); radarData.setAlertMessage((AlertMessage) o);
} else { } else {
size -= record.getSizeInBytes(); size -= record.getSizeInBytes();

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.common.dataplugin.scan; package com.raytheon.uf.common.dataplugin.scan;
import java.io.ByteArrayInputStream;
import java.util.Date; import java.util.Date;
import java.util.Set; import java.util.Set;
@ -68,14 +67,15 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* *
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* 03/17/10 2521 D. Hladky Initial release * 03/17/10 2521 D. Hladky Initial release
* 02/01/13 1649 D. Hladky better logging, * 02/01/13 1649 D. Hladky better logging,
* Feb 28, 2013 1731 bsteffen Optimize construction of scan resource. * Feb 28, 2013 1731 bsteffen Optimize construction of scan resource.
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime * Apr 04, 2013 1846 bkowal Added an index on refTime and forecastTime
* Apr 8, 2013 1293 bkowal Removed references to hdffileid. * Apr 08, 2013 1293 bkowal Removed references to hdffileid.
* Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation. * Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation.
* May 07, 2013 1869 bsteffen Remove dataURI column from * May 07, 2013 1869 bsteffen Remove dataURI column from
* PluginDataObject. * PluginDataObject.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -90,12 +90,8 @@ import com.raytheon.uf.common.status.UFStatus.Priority;
* Both refTime and forecastTime are included in the refTimeIndex since * Both refTime and forecastTime are included in the refTimeIndex since
* forecastTime is unlikely to be used. * forecastTime is unlikely to be used.
*/ */
@org.hibernate.annotations.Table( @org.hibernate.annotations.Table(appliesTo = "scan", indexes = { @Index(name = "scan_refTimeIndex", columnNames = {
appliesTo = "scan", "refTime", "forecastTime" }) })
indexes = {
@Index(name = "scan_refTimeIndex", columnNames = { "refTime", "forecastTime" } )
}
)
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
@DynamicSerialize @DynamicSerialize
@ -107,7 +103,7 @@ public class ScanRecord extends PersistablePluginDataObject {
private static final long serialVersionUID = 5983810116816447875L; private static final long serialVersionUID = 5983810116816447875L;
private static final IUFStatusHandler statusHandler = UFStatus private static final IUFStatusHandler statusHandler = UFStatus
.getHandler(ScanRecord.class); .getHandler(ScanRecord.class);
@Column(length = 7) @Column(length = 7)
@DataURI(position = 1) @DataURI(position = 1)
@ -297,10 +293,8 @@ public class ScanRecord extends PersistablePluginDataObject {
*/ */
public void setTableData(ByteDataRecord byteData) public void setTableData(ByteDataRecord byteData)
throws SerializationException { throws SerializationException {
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(byteData.getByteData());
setTableData((ScanTableData<?>) o); setTableData((ScanTableData<?>) o);
} }
@ -316,7 +310,8 @@ public class ScanRecord extends PersistablePluginDataObject {
getDataURI(), getType(), Request.ALL); getDataURI(), getType(), Request.ALL);
setTableData(byteData); setTableData(byteData);
} catch (Throwable e) { } catch (Throwable e) {
statusHandler.handle(Priority.ERROR, "Couldn't load Table data!" + getDataURI()); statusHandler.handle(Priority.ERROR, "Couldn't load Table data!"
+ getDataURI());
} }
} }
@ -329,13 +324,13 @@ public class ScanRecord extends PersistablePluginDataObject {
try { try {
ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve( ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve(
getDataURI(), getType() + "/sounding", Request.ALL); getDataURI(), getType() + "/sounding", Request.ALL);
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setSoundingData((SoundingData) o); setSoundingData((SoundingData) o);
} catch (Throwable e) { } catch (Throwable e) {
statusHandler.handle(Priority.ERROR, "Couldn't load Sounding data!" + getDataURI()); statusHandler.handle(Priority.ERROR, "Couldn't load Sounding data!"
+ getDataURI());
} }
} }
@ -348,13 +343,13 @@ public class ScanRecord extends PersistablePluginDataObject {
try { try {
ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve( ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve(
getDataURI(), getType() + "/model", Request.ALL); getDataURI(), getType() + "/model", Request.ALL);
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setModelData((ModelData) o); setModelData((ModelData) o);
} catch (Throwable e) { } catch (Throwable e) {
statusHandler.handle(Priority.ERROR, "Couldn't load Model data!" + getDataURI()); statusHandler.handle(Priority.ERROR, "Couldn't load Model data!"
+ getDataURI());
} }
} }

View file

@ -20,16 +20,13 @@
package com.raytheon.uf.common.localization.msgs; package com.raytheon.uf.common.localization.msgs;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import javax.xml.bind.JAXBException; import javax.xml.bind.JAXBException;
import com.raytheon.uf.common.localization.exception.LocalizationException; import com.raytheon.uf.common.localization.exception.LocalizationException;
import com.raytheon.uf.common.serialization.DynamicSerializationManager; import com.raytheon.uf.common.serialization.DynamicSerializationManager;
import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType;
import com.raytheon.uf.common.serialization.SerializationException; import com.raytheon.uf.common.serialization.SerializationException;
import com.raytheon.uf.common.serialization.SerializationUtil; import com.raytheon.uf.common.serialization.SerializationUtil;
import com.raytheon.uf.common.serialization.DynamicSerializationManager.SerializationType;
/** /**
* Utility class for converting and constructing localization messages * Utility class for converting and constructing localization messages
@ -184,22 +181,12 @@ public class UtilityMessageMarshaller {
private static Object deserializeBinary(byte[] message, Class<?> c) private static Object deserializeBinary(byte[] message, Class<?> c)
throws LocalizationException { throws LocalizationException {
ByteArrayInputStream bais = null;
try { try {
DynamicSerializationManager mgr = DynamicSerializationManager DynamicSerializationManager mgr = DynamicSerializationManager
.getManager(SerializationType.Thrift); .getManager(SerializationType.Thrift);
bais = new ByteArrayInputStream(message); return mgr.deserialize(message);
return mgr.deserialize(bais);
} catch (SerializationException e) { } catch (SerializationException e) {
throw new LocalizationException("Unable to deserialize: ", e); throw new LocalizationException("Unable to deserialize: ", e);
} finally {
try {
if (bais != null)
bais.close();
} catch (IOException e) {
// ignore
}
} }
} }

View file

@ -1,11 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.raytheon.uf.common.qpf</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View file

@ -91,6 +91,7 @@ import com.vividsolutions.jts.geom.Geometry;
* serialization adapter is encoded * serialization adapter is encoded
* in serialization stream. * in serialization stream.
* Nov 02, 2012 1302 djohnson Remove field level adapters, they break python serialization. * Nov 02, 2012 1302 djohnson Remove field level adapters, they break python serialization.
* Aug 06, 2013 2228 njensen Added deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -256,7 +257,6 @@ public class DynamicSerializationManager {
Object obj = deserialize(ctx); Object obj = deserialize(ctx);
ctx.readMessageEnd(); ctx.readMessageEnd();
return obj; return obj;
} }
/** /**
@ -273,6 +273,22 @@ public class DynamicSerializationManager {
return ((ThriftSerializationContext) ctx).deserializeMessage(); return ((ThriftSerializationContext) ctx).deserializeMessage();
} }
/**
* Deserialize an object from a byte[]
*
* @param data
* @return
* @throws SerializationException
*/
public Object deserialize(byte[] data) throws SerializationException {
IDeserializationContext ctx = this.builder.buildDeserializationContext(
data, this);
ctx.readMessageStart();
Object obj = deserialize(ctx);
ctx.readMessageEnd();
return obj;
}
public static <T> void registerAdapter(Class<? extends T> clazz, public static <T> void registerAdapter(Class<? extends T> clazz,
ISerializationTypeAdapter<T> adapter) { ISerializationTypeAdapter<T> adapter) {
SerializationMetadata md = new SerializationMetadata(); SerializationMetadata md = new SerializationMetadata();

View file

@ -31,6 +31,7 @@ import java.io.OutputStream;
* Date Ticket# Engineer Description * Date Ticket# Engineer Description
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Aug 12, 2008 chammack Initial creation * Aug 12, 2008 chammack Initial creation
* Aug 06, 2013 2228 njensen Added buildDeserializationContext(byte[], dsm)
* *
* </pre> * </pre>
* *
@ -63,4 +64,16 @@ public interface ISerializationContextBuilder {
public IDeserializationContext buildDeserializationContext( public IDeserializationContext buildDeserializationContext(
InputStream data, DynamicSerializationManager manager); InputStream data, DynamicSerializationManager manager);
/**
* Build a deserialization context
*
* @param data
* the bytes of the data
* @param manager
* the serialization manager
* @return a deserialization context
*/
public IDeserializationContext buildDeserializationContext(byte[] data,
DynamicSerializationManager manager);
} }

View file

@ -19,9 +19,7 @@
**/ **/
package com.raytheon.uf.common.serialization; package com.raytheon.uf.common.serialization;
import java.io.ByteArrayInputStream;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.List; import java.util.List;
@ -47,6 +45,7 @@ import com.raytheon.uf.common.util.ServiceLoaderUtil;
* Feb 07, 2013 1543 djohnson Use ServiceLoader to find how to load jaxbable classes, defaulting to SerializableManager. * Feb 07, 2013 1543 djohnson Use ServiceLoader to find how to load jaxbable classes, defaulting to SerializableManager.
* Mar 21, 2013 1794 djohnson ServiceLoaderUtil now requires the requesting class. * Mar 21, 2013 1794 djohnson ServiceLoaderUtil now requires the requesting class.
* May 01, 2013 1968 djohnson Prevent deadlock due to SerializableManager threads needing to serialize things. * May 01, 2013 1968 djohnson Prevent deadlock due to SerializableManager threads needing to serialize things.
* Aug 06, 2013 2228 njensen More efficient transformFromThrift(Class, byte[])
* *
* </pre> * </pre>
* *
@ -351,20 +350,10 @@ public final class SerializationUtil {
throws SerializationException { throws SerializationException {
DynamicSerializationManager dsm = DynamicSerializationManager DynamicSerializationManager dsm = DynamicSerializationManager
.getManager(SerializationType.Thrift); .getManager(SerializationType.Thrift);
ByteArrayInputStream bais = null;
try { try {
bais = new ByteArrayInputStream(bytes); return clazz.cast(dsm.deserialize(bytes));
return clazz.cast(dsm.deserialize(bais));
} catch (ClassCastException cce) { } catch (ClassCastException cce) {
throw new SerializationException(cce); throw new SerializationException(cce);
} finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
// ignore
}
}
} }
} }

View file

@ -58,6 +58,8 @@ import org.apache.thrift.transport.TTransport;
* Jun 12, 2013 2102 njensen Added max read length to prevent out * Jun 12, 2013 2102 njensen Added max read length to prevent out
* of memory errors due to bad stream * of memory errors due to bad stream
* Jul 23, 2013 2215 njensen Updated for thrift 0.9.0 * Jul 23, 2013 2215 njensen Updated for thrift 0.9.0
* Aug 06, 2013 2228 njensen Overrode readBinary() to ensure it
* doesn't read too much
* *
* </pre> * </pre>
* *
@ -99,6 +101,15 @@ public class SelfDescribingBinaryProtocol extends TBinaryProtocol {
this.setReadLength(MAX_READ_LENGTH); this.setReadLength(MAX_READ_LENGTH);
} }
@Override
public ByteBuffer readBinary() throws TException {
int size = readI32();
checkReadLength(size);
byte[] buf = new byte[size];
trans_.readAll(buf, 0, size);
return ByteBuffer.wrap(buf);
}
/* /*
* (non-Javadoc) * (non-Javadoc)
* *

View file

@ -23,6 +23,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import org.apache.thrift.transport.TIOStreamTransport; import org.apache.thrift.transport.TIOStreamTransport;
import org.apache.thrift.transport.TMemoryInputTransport;
import org.apache.thrift.transport.TTransport; import org.apache.thrift.transport.TTransport;
import com.raytheon.uf.common.serialization.DynamicSerializationManager; import com.raytheon.uf.common.serialization.DynamicSerializationManager;
@ -39,6 +40,7 @@ import com.raytheon.uf.common.serialization.ISerializationContextBuilder;
* ------------ ---------- ----------- -------------------------- * ------------ ---------- ----------- --------------------------
* Aug 12, 2008 chammack Initial creation * Aug 12, 2008 chammack Initial creation
* Jul 23, 2013 2215 njensen Updated for thrift 0.9.0 * Jul 23, 2013 2215 njensen Updated for thrift 0.9.0
* Aug 06, 2013 2228 njensen Added buildDeserializationContext(byte[], dsm)
* *
* </pre> * </pre>
* *
@ -83,4 +85,15 @@ public class ThriftSerializationContextBuilder implements
return new ThriftSerializationContext(proto, manager); return new ThriftSerializationContext(proto, manager);
} }
@Override
public IDeserializationContext buildDeserializationContext(byte[] data,
DynamicSerializationManager manager) {
TTransport transport = new TMemoryInputTransport(data);
SelfDescribingBinaryProtocol proto = new SelfDescribingBinaryProtocol(
transport);
return new ThriftSerializationContext(proto, manager);
}
} }

View file

@ -1,4 +1,3 @@
package gov.noaa.nws.ncep.edex.plugin.mosaic.common; package gov.noaa.nws.ncep.edex.plugin.mosaic.common;
import gov.noaa.nws.ncep.edex.plugin.mosaic.util.MosaicConstants; import gov.noaa.nws.ncep.edex.plugin.mosaic.util.MosaicConstants;
@ -8,7 +7,6 @@ import gov.noaa.nws.ncep.edex.plugin.mosaic.util.level3.SymbologyBlock;
import gov.noaa.nws.ncep.edex.plugin.mosaic.util.level3.SymbologyPacket; import gov.noaa.nws.ncep.edex.plugin.mosaic.util.level3.SymbologyPacket;
import gov.noaa.nws.ncep.edex.plugin.mosaic.util.level3.SymbologyPoint; import gov.noaa.nws.ncep.edex.plugin.mosaic.util.level3.SymbologyPoint;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
@ -67,10 +65,11 @@ import com.vividsolutions.jts.geom.Coordinate;
* Extracted prod name from mosaicInfo.txt * Extracted prod name from mosaicInfo.txt
* 6/2012 825 G. Hull rm prodName from URI. Use prodCode where needed. * 6/2012 825 G. Hull rm prodName from URI. Use prodCode where needed.
* 09/2012 B. Hebbard Merge out RTS changes from OB12.9.1 * 09/2012 B. Hebbard Merge out RTS changes from OB12.9.1
* Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime * Apr 4, 2013 1846 bkowal Added an index on refTime and forecastTime
* Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation. * Apr 12, 2013 1857 bgonzale Added SequenceGenerator annotation.
* May 07, 2013 1869 bsteffen Remove dataURI column from * May 07, 2013 1869 bsteffen Remove dataURI column from
* PluginDataObject. * PluginDataObject.
* Aug 06, 2013 2228 njensen Use deserialize(byte[])
* *
* </pre> * </pre>
* *
@ -80,7 +79,6 @@ import com.vividsolutions.jts.geom.Coordinate;
* @version 1.0 * @version 1.0
*/ */
@Entity @Entity
@SequenceGenerator(initialValue = 1, name = PluginDataObject.ID_GEN, sequenceName = "mosaicseq") @SequenceGenerator(initialValue = 1, name = PluginDataObject.ID_GEN, sequenceName = "mosaicseq")
@Table(name = "mosaic", uniqueConstraints = { @UniqueConstraint(columnNames = { "dataURI" }) }) @Table(name = "mosaic", uniqueConstraints = { @UniqueConstraint(columnNames = { "dataURI" }) })
@ -88,12 +86,8 @@ import com.vividsolutions.jts.geom.Coordinate;
* Both refTime and forecastTime are included in the refTimeIndex since * Both refTime and forecastTime are included in the refTimeIndex since
* forecastTime is unlikely to be used. * forecastTime is unlikely to be used.
*/ */
@org.hibernate.annotations.Table( @org.hibernate.annotations.Table(appliesTo = "mosaic", indexes = { @Index(name = "mosaic_refTimeIndex", columnNames = {
appliesTo = "mosaic", "refTime", "forecastTime" }) })
indexes = {
@Index(name = "mosaic_refTimeIndex", columnNames = { "refTime", "forecastTime" } )
}
)
@Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL) @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
@XmlRootElement @XmlRootElement
@XmlAccessorType(XmlAccessType.NONE) @XmlAccessorType(XmlAccessType.NONE)
@ -110,7 +104,7 @@ public class MosaicRecord extends PersistablePluginDataObject implements
private Integer productCode; private Integer productCode;
@Column @Column
@DataURI(position=2) @DataURI(position = 2)
@DynamicSerializeElement @DynamicSerializeElement
@XmlElement(nillable = false) @XmlElement(nillable = false)
private Integer resolution; private Integer resolution;
@ -272,10 +266,9 @@ public class MosaicRecord extends PersistablePluginDataObject implements
// getDataURI(), "Symbology"); // getDataURI(), "Symbology");
ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve( ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve(
getDataURI(), "Symbology", Request.ALL); getDataURI(), "Symbology", Request.ALL);
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setSymbologyBlock((SymbologyBlock) o); setSymbologyBlock((SymbologyBlock) o);
} catch (Throwable e) { } catch (Throwable e) {
setSymbologyBlock(null); setSymbologyBlock(null);
@ -284,10 +277,9 @@ public class MosaicRecord extends PersistablePluginDataObject implements
try { try {
ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve( ByteDataRecord byteData = (ByteDataRecord) dataStore.retrieve(
getDataURI(), "ProductVals", Request.ALL); getDataURI(), "ProductVals", Request.ALL);
ByteArrayInputStream bais = new ByteArrayInputStream(
byteData.getByteData());
Object o = DynamicSerializationManager.getManager( Object o = DynamicSerializationManager.getManager(
SerializationType.Thrift).deserialize(bais); SerializationType.Thrift).deserialize(
byteData.getByteData());
setProductVals((HashMap<MosaicConstants.MapValues, Map<String, Map<MosaicConstants.MapValues, String>>>) o); setProductVals((HashMap<MosaicConstants.MapValues, Map<String, Map<MosaicConstants.MapValues, String>>>) o);
} catch (Throwable e) { } catch (Throwable e) {
setProductVals(null); setProductVals(null);

View file

@ -19,7 +19,6 @@
**/ **/
package com.raytheon.uf.common.message; package com.raytheon.uf.common.message;
import java.io.ByteArrayInputStream;
import java.net.InetAddress; import java.net.InetAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Random; import java.util.Random;
@ -89,8 +88,7 @@ public class TestWsIdAdapter {
Test outTest = null; Test outTest = null;
try { try {
ByteArrayInputStream bais = new ByteArrayInputStream(bdata); outTest = (Test) dmgr.deserialize(bdata);
outTest = (Test) dmgr.deserialize(bais);
} catch (Throwable e) { } catch (Throwable e) {
e.printStackTrace(); e.printStackTrace();
Assert.fail(e.getMessage()); Assert.fail(e.getMessage());