List of usage examples for org.apache.commons.lang SerializationUtils deserialize
public static Object deserialize(byte[] objectData)
Deserializes a single Object
from an array of bytes.
From source file:com.impetus.ankush.common.domain.NodeMonitoring.java
/** * Gets the technology service status.//from w w w. j a va 2 s . c o m * * @return the serviceStatus */ @Transient public Map<String, Map<String, Boolean>> getTechnologyServiceStatus() { // Get technology status bytes if null return null. if (getTechnologyServiceBytes() == null) { return null; } // serializing the data. return (HashMap<String, Map<String, Boolean>>) SerializationUtils.deserialize(getTechnologyServiceBytes()); }
From source file:com.impetus.ankush.common.domain.Operation.java
/** * Gets the cluster conf.//from www .j a va 2 s. c o m * * @return the cluster conf */ @Transient public HashMap<String, Object> getData() { if (getDataBytes() == null) { return null; } return (HashMap<String, Object>) SerializationUtils.deserialize(getDataBytes()); }
From source file:mitm.common.mail.MailAddressTest.java
@Test public void testDeserialize() throws Exception { MailAddress address = new MailAddress("test@example.com"); String base64Serialized = "rO0ABXNyAB1vcmcuYXBhY2hlLm1haWxldC5NYWlsQWRkcmVzcyaRkoRtx3ukAgADSQADcG9zTAAE" + "aG9zdHQAEkxqYXZhL2xhbmcvU3RyaW5nO0wABHVzZXJxAH4AAXhwAAAAEHQAC2V4YW1wbGUuY29t" + "dAAEdGVzdA=="; MailAddress copy = (MailAddress) SerializationUtils .deserialize(Base64.decodeBase64(MiscStringUtils.toAsciiBytes(base64Serialized))); assertEquals(address, copy);// w ww. j a v a 2 s.c om }
From source file:com.janrain.backplane.server.MessageProcessor.java
/** * Processor to pull messages off queue and make them available * */// w w w. j a va 2s . co m private void insertMessages() { try { logger.info("v1 message processor started"); List<String> insertionTimes = new ArrayList<String>(); do { logger.debug("beginning message processor loop"); Jedis jedis = null; try { jedis = Redis.getInstance().getWriteJedis(); logger.debug("retrieved jedis connection: " + jedis.toString()); // set watch on V1_LAST_ID // needs to be set before retrieving the value stored at this key jedis.watch(V1_LAST_ID); Pair<String, Date> lastIdAndDate = getLastMessageId(jedis); String newId = lastIdAndDate.getLeft(); // retrieve a handful of messages (ten) off the queue for processing List<byte[]> messagesToProcess = jedis .lrange(RedisBackplaneMessageDAO.V1_MESSAGE_QUEUE.getBytes(), 0, 9); logger.debug("number of messages to process: " + messagesToProcess.size()); // only enter the next block if we have messages to process if (messagesToProcess.size() > 0) { Transaction transaction = jedis.multi(); insertionTimes.clear(); // <ATOMIC> - redis transaction for (byte[] messageBytes : messagesToProcess) { if (messageBytes != null) { BackplaneMessage backplaneMessage = (BackplaneMessage) SerializationUtils .deserialize(messageBytes); if (backplaneMessage != null) { // retrieve the expiration config per the bus BusConfig1 busConfig1 = DaoFactory.getBusDAO().get(backplaneMessage.getBus()); int retentionTimeSeconds = 60; int retentionTimeStickySeconds = 3600; if (busConfig1 != null) { // should be here in normal flow retentionTimeSeconds = busConfig1.getRetentionTimeSeconds(); retentionTimeStickySeconds = busConfig1.getRetentionTimeStickySeconds(); } String oldId = backplaneMessage.getIdValue(); insertionTimes.add(oldId); // TOTAL ORDER GUARANTEE // verify that the date portion of the new message ID is greater than all existing message ID dates // if not, uptick id by 1 ms and insert // this means that all message ids have unique time stamps, even if they // arrived at the same time. lastIdAndDate = backplaneMessage.updateId(lastIdAndDate); newId = backplaneMessage.getIdValue(); // messageTime is guaranteed to be a unique identifier of the message // because of the TOTAL ORDER mechanism above long messageTime = BackplaneMessage.getDateFromId(newId).getTime(); // save the individual message by key transaction.set(RedisBackplaneMessageDAO.getKey(newId), SerializationUtils.serialize(backplaneMessage)); // set the message TTL if (backplaneMessage.isSticky()) { transaction.expire(RedisBackplaneMessageDAO.getKey(newId), retentionTimeStickySeconds); } else { transaction.expire(RedisBackplaneMessageDAO.getKey(newId), retentionTimeSeconds); } // add message id to channel list transaction.rpush( RedisBackplaneMessageDAO.getChannelKey(backplaneMessage.getChannel()), newId.getBytes()); // add message id to sorted set of all message ids as an index String metaData = backplaneMessage.getBus() + " " + backplaneMessage.getChannel() + " " + newId; transaction.zadd(RedisBackplaneMessageDAO.V1_MESSAGES.getBytes(), messageTime, metaData.getBytes()); // add message id to sorted set keyed by bus as an index transaction.zadd(RedisBackplaneMessageDAO.getBusKey(backplaneMessage.getBus()), messageTime, newId.getBytes()); // make sure all subscribers get the update transaction.publish("alerts", newId); // pop one message off the queue - which will only happen if this transaction is successful transaction.lpop(RedisBackplaneMessageDAO.V1_MESSAGE_QUEUE); logger.info("pipelined message " + oldId + " -> " + newId); } } } // for messages transaction.set(V1_LAST_ID, newId); logger.info("processing transaction with " + insertionTimes.size() + " message(s)"); if (transaction.exec() == null) { // the transaction failed continue; } // </ATOMIC> - redis transaction logger.info("flushed " + insertionTimes.size() + " messages"); long now = System.currentTimeMillis(); for (String insertionId : insertionTimes) { Date oldIdDate = BackplaneMessage.getDateFromId(insertionId); long diff = now - oldIdDate.getTime(); timeInQueue.update(diff); if (diff < 0 || diff > 2880000) { logger.warn("time diff is bizarre at: " + diff + "; now: " + DateTimeUtils.ISO8601.get().format(new Date(now)) + ", oldId: " + DateTimeUtils.ISO8601.get().format(oldIdDate)); } } Thread.sleep(150); } // messagesToProcess > 0 } catch (Exception e) { try { logger.warn("error " + e.getMessage()); if (jedis != null) { Redis.getInstance().releaseBrokenResourceToPool(jedis); jedis = null; } } catch (Exception e1) { //ignore } Thread.sleep(2000); } finally { try { if (jedis != null) { jedis.unwatch(); Redis.getInstance().releaseToPool(jedis); } } catch (Exception e) { Redis.getInstance().releaseBrokenResourceToPool(jedis); } } } while (isLeader()); } catch (Exception e) { logger.warn("exception thrown in message processor thread: " + e.getMessage()); } }
From source file:mitm.application.djigzo.mail.MailContainerTest.java
@Test public void testDeserialized() throws Exception { String hex = "ACED00057372002A6D69746D2E6170706C69636174696F6E2E646A69677A6F2E6D61696C2E4D61696C436F6E74616" + "96E657200000000000000010300014C00046D61696C7400184C6F72672F6170616368652F6D61696C65742F4D61696C3B7" + "870770800000000000000017372001E6F72672E6170616368652E6A616D65732E636F72652E4D61696C496D706CC4780DE" + "5BCCFDDAC03000A4C000A617474726962757465737400134C6A6176612F7574696C2F486173684D61703B4C000C6572726" + "F724D6573736167657400124C6A6176612F6C616E672F537472696E673B4C000B6C617374557064617465647400104C6A6" + "176612F7574696C2F446174653B4C00076D6573736167657400214C6A617661782F6D61696C2F696E7465726E65742F4D6" + "96D654D6573736167653B4C00046E616D6571007E00054C000A726563697069656E74737400164C6A6176612F7574696C2" + "F436F6C6C656374696F6E3B4C000A72656D6F74654164647271007E00054C000A72656D6F7465486F737471007E00054C0" + "00673656E64657274001F4C6F72672F6170616368652F6D61696C65742F4D61696C416464726573733B4C0005737461746" + "571007E000578707372001D6F72672E6170616368652E6D61696C65742E4D61696C41646472657373269192846DC77BA40" + "20003490003706F734C0004686F737471007E00054C00047573657271007E000578700000001274000B6578616D706C652" + "E636F6D74000673656E646572737200136A6176612E7574696C2E41727261794C6973747881D21D99C7619D03000149000" + "473697A6578700000000277040000000A7371007E000B0000001174000B6578616D706C652E636F6D74000574657374317" + "371007E000B0000001174000B6578616D706C652E636F6D740005746573743178740004726F6F747074000474657374740" + "0096C6F63616C686F73747400093132372E302E302E317372000E6A6176612E7574696C2E44617465686A81014B5974190" + "30000787077080000012D94980CFF78737200116A6176612E7574696C2E486173684D61700507DAC1C31660D1030002460" + "00A6C6F6164466163746F724900097468726573686F6C6478703F4000000000000C7708000000100000000274000574657" + "3743174000431323334740005746573743274000435363738787878"; MailContainer deserialized = (MailContainer) SerializationUtils.deserialize(HexUtils.hexDecode(hex)); assertEquals(Arrays.asList(new MailAddress("test1@example.com"), new MailAddress("test1@example.com")), deserialized.getMail().getRecipients()); assertEquals(new MailAddress("sender@example.com"), deserialized.getMail().getSender()); assertEquals("root", deserialized.getMail().getState()); assertEquals(null, deserialized.getMail().getErrorMessage()); assertEquals("test", deserialized.getMail().getName()); assertEquals("localhost", deserialized.getMail().getRemoteHost()); assertEquals("127.0.0.1", deserialized.getMail().getRemoteAddr()); assertEquals("1234", deserialized.getMail().getAttribute("test1")); assertEquals("5678", deserialized.getMail().getAttribute("test2")); // the message should not be serialized assertNull(deserialized.getMail().getMessage()); }
From source file:com.janrain.backplane.server.dao.redis.RedisBackplaneMessageDAO.java
@Override public BackplaneMessage get(String key) { byte[] messageBytes = Redis.getInstance().get(key.getBytes()); if (messageBytes != null) { return (BackplaneMessage) SerializationUtils.deserialize(messageBytes); }//from ww w.j a v a 2 s. co m return null; }
From source file:com.ephesoft.dcma.batch.dao.impl.BatchInstancePluginPropertiesDao.java
/** * This method is to get the plugin properties. * /* www .j a v a 2s . co m*/ * @param batchInstanceIdentifier String. * @return {@link BatchPluginPropertyContainer} */ @Cacheable(cacheName = "pluginPropertiesCache", keyGenerator = @KeyGenerator(name = "StringCacheKeyGenerator", properties = @Property(name = "includeMethod", value = "false"))) public BatchPluginPropertyContainer getPluginProperties(final String batchInstanceIdentifier) { String loggingPrefix = BatchConstants.LOG_AREA + batchInstanceIdentifier; if (IS_DEBUG_ENABLE) { LOGGER.debug(loggingPrefix + " : Executing getPluginProperties(String) API of BatchInstancePluginPropertiesDao."); } BatchPluginPropertyContainer container = null; final String localFolderLocation = batchInstanceDao .getSystemFolderForBatchInstanceId(batchInstanceIdentifier); boolean isContainerCreated = false; final String pathToPropertiesFolder = localFolderLocation + File.separator + "properties"; final File file = new File(pathToPropertiesFolder); if (!file.exists()) { file.mkdir(); if (IS_DEBUG_ENABLE) { LOGGER.debug(loggingPrefix + " : folder created " + pathToPropertiesFolder); } } final File serializedFile = new File( pathToPropertiesFolder + File.separator + batchInstanceIdentifier + '.' + EXTN); if (serializedFile.exists()) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(serializedFile); container = (BatchPluginPropertyContainer) SerializationUtils.deserialize(fileInputStream); isContainerCreated = true; } catch (Exception exception) { LOGGER.error( loggingPrefix + " : Error during de-serializing the properties for this Batch instance: ", exception); isContainerCreated = false; } finally { try { if (fileInputStream != null) { fileInputStream.close(); } } catch (IOException exception) { LOGGER.error(loggingPrefix + " : Problem closing stream for file : " + serializedFile.getName(), exception); } } } if (!isContainerCreated) { final List<BatchClassPluginConfig> batchClassPluginConfigs = batchClassPluginConfigDao .getAllPluginPropertiesForBatchInstance(batchInstanceIdentifier); // to lazily load KVPageProcess objects for (final BatchClassPluginConfig batchClassPluginConfig : batchClassPluginConfigs) { for (final KVPageProcess eachKvPageProcess : batchClassPluginConfig.getKvPageProcesses()) { if (IS_DEBUG_ENABLE && eachKvPageProcess != null) { LOGGER.debug(loggingPrefix + " : Key pattern is " + eachKvPageProcess.getKeyPattern()); } } } final List<BatchClassDynamicPluginConfig> batchClassDynamicPluginConfigs = batchClassDynamicPluginConfigDao .getAllDynamicPluginPropertiesForBatchInstance(batchInstanceIdentifier); container = new BatchPluginPropertyContainer(String.valueOf(batchInstanceIdentifier)); container.populate(batchClassPluginConfigs); container.populateDynamicPluginConfigs(batchClassDynamicPluginConfigs); final List<DocumentType> documentTypes = documentTypeService .getDocTypeByBatchInstanceIdentifier(batchInstanceIdentifier); container.populateDocumentTypes(documentTypes, batchInstanceIdentifier); FileOutputStream fileOutputStream = null; try { fileOutputStream = new FileOutputStream(serializedFile); SerializationUtils.serialize(container, fileOutputStream); } catch (Exception exception) { LOGGER.error(loggingPrefix + " : Error during serializing properties for this Batch instance.", exception); } finally { try { if (fileOutputStream != null) { fileOutputStream.close(); } } catch (IOException exception) { LOGGER.error(loggingPrefix + " : Problem closing stream for file " + serializedFile.getName(), exception); } } } if (IS_DEBUG_ENABLE) { LOGGER.debug(loggingPrefix + " : Executed getPluginProperties(String) API of BatchInstancePluginPropertiesDao successfully."); } return container; }
From source file:com.liveramp.cascading_ext.bloom.BloomFilter.java
@Override public void readFields(DataInput in) throws IOException { numHashes = in.readInt();/*from w w w . j av a2 s .c o m*/ vectorSize = in.readLong(); numElems = in.readLong(); byte[] bytes = new byte[FixedSizeBitSet.getNumBytesToStore(vectorSize)]; in.readFully(bytes); bits = new FixedSizeBitSet(vectorSize, bytes); byte[] serializedHashFunction = new byte[in.readInt()]; in.readFully(serializedHashFunction); hashFunction = (HashFunction) SerializationUtils.deserialize(serializedHashFunction); }
From source file:com.janrain.backplane2.server.V2MessageProcessor.java
private void processSingleBatchOfPendingMessages() throws Exception { Jedis jedis = null;// w ww .j a v a2s . c om try { jedis = Redis.getInstance().getWriteJedis(); List<String> insertionTimes = new ArrayList<String>(); // set watch on V1_LAST_ID // needs to be set before retrieving the value stored at this key jedis.watch(V2_LAST_ID); Pair<String, Date> lastIdAndDate = getLastMessageId(jedis); String newId = lastIdAndDate.getLeft(); // retrieve a handful of messages (ten) off the queue for processing List<byte[]> messagesToProcess = jedis.lrange(RedisBackplaneMessageDAO.V2_MESSAGE_QUEUE.getBytes(), 0, 9); // only enter the next block if we have messages to process if (messagesToProcess.size() > 0) { Transaction transaction = jedis.multi(); insertionTimes.clear(); // <ATOMIC> - redis transaction for (byte[] messageBytes : messagesToProcess) { if (messageBytes != null) { BackplaneMessage backplaneMessage = (BackplaneMessage) SerializationUtils .deserialize(messageBytes); if (backplaneMessage != null) { newId = processSingleMessage(backplaneMessage, transaction, insertionTimes, lastIdAndDate); } } } transaction.set(V2_LAST_ID, newId); logger.info("processing transaction with " + insertionTimes.size() + " v2 message(s)"); List<Object> results = transaction.exec(); if (results == null || results.size() == 0) { logger.warn("transaction failed! - halting work for now"); return; } // </ATOMIC> - redis transaction logger.info("flushed " + insertionTimes.size() + " v2 messages"); long now = System.currentTimeMillis(); for (String insertionId : insertionTimes) { long diff = now - com.janrain.backplane.server.BackplaneMessage.getDateFromId(insertionId).getTime(); timeInQueue.update(diff); if (diff < 0 || diff > 2880000) { logger.warn("time diff is bizarre at: " + diff); } } } } catch (Exception e) { // if we get here, something bonked, like a connection to the redis server logger.warn("an error occurred while trying to process v2 message batch: " + e.getMessage()); Redis.getInstance().releaseBrokenResourceToPool(jedis); jedis = null; throw e; } finally { try { if (jedis != null) { jedis.unwatch(); Redis.getInstance().releaseToPool(jedis); } } catch (Exception e) { // ignore } } }
From source file:com.zia.freshdocs.preference.CMISPreferencesManager.java
@SuppressWarnings("unchecked") public Set<NodeRef> getFavorites(Context ctx) { Set<NodeRef> favorites = new HashSet<NodeRef>(); SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(ctx); String enc = null;//from w w w . j a va2s. c om if (sharedPrefs.contains(FAVORITES_KEY)) { enc = sharedPrefs.getString(FAVORITES_KEY, null); if (enc != null) { byte[] repr = Base64.decodeBase64(enc.getBytes()); Object obj = SerializationUtils.deserialize(repr); if (obj != null) { favorites = (Set<NodeRef>) obj; } } } return favorites; }