List of usage examples for org.apache.commons.lang3 SerializationUtils serialize
public static byte[] serialize(final Serializable obj)
Serializes an Object to a byte array for storage/serialization.
From source file:com.dangdang.ddframe.job.cloud.executor.TaskExecutorThreadTest.java
private byte[] serialize(final Map<String, String> jobConfigurationContext) { // CHECKSTYLE:OFF LinkedHashMap<String, Object> result = new LinkedHashMap<>(2, 1); // CHECKSTYLE:ON ShardingContexts shardingContexts = new ShardingContexts(taskId, "test_job", 1, "", Collections.singletonMap(1, "a")); result.put("shardingContext", shardingContexts); result.put("jobConfigContext", jobConfigurationContext); return SerializationUtils.serialize(result); }
From source file:com.arpnetworking.steno.LogValueMapFactoryTest.java
@Test public void testSerialization() { final Widget w = new Widget("foo"); final LogValueMapFactory.LogValueMap mapWithReference = LogValueMapFactory.builder(w).build(); Assert.assertTrue(mapWithReference.getTarget().isPresent()); Assert.assertSame(w, mapWithReference.getTarget().get()); final byte[] serializedMap = SerializationUtils.serialize(mapWithReference); final LogValueMapFactory.LogValueMap deserializedMap = SerializationUtils.deserialize(serializedMap); Assert.assertFalse(deserializedMap.getTarget().isPresent()); }
From source file:cc.gospy.core.remote.rabbitmq.RemoteServiceProvider.java
private void publish(Task task) throws IOException { AMQP.BasicProperties properties = !withPriority ? MessageProperties.PERSISTENT_BASIC : new AMQP.BasicProperties.Builder().contentType("application/octet-stream").deliveryMode(2) .priority((int) task.getPriority()).build(); channel.basicPublish(EXCHANGE, dispatcher.getTargetQueue(task), properties, SerializationUtils.serialize(task)); duplicateRemover.record(task);/*ww w.j a va 2 s .c o m*/ }
From source file:fredboat.db.entity.SearchResult.java
public void setSearchResult(AudioPlayerManager playerManager, AudioPlaylist searchResult) { this.serializedSearchResult = SerializationUtils .serialize(new SerializableAudioPlaylist(playerManager, searchResult)); }
From source file:com.splicemachine.derby.stream.output.update.UpdateTableWriterBuilder.java
public String getUpdateTableWriterBuilderBase64String() throws IOException, StandardException { return Base64.encodeBase64String(SerializationUtils.serialize(this)); }
From source file:com.splicemachine.derby.stream.output.insert.InsertTableWriterBuilder.java
public String getInsertTableWriterBuilderBase64String() throws IOException, StandardException { return Base64.encodeBase64String(SerializationUtils.serialize(this)); }
From source file:com.gargoylesoftware.htmlunit.WebClient2Test.java
/** * Background tasks that have been registered before the serialization should * wake up and run normally after the deserialization. * Until now (2.7-SNAPSHOT 17.09.09) HtmlUnit has probably never supported it. * This is currently not requested and this test is just to document the current status. * @throws Exception if an error occurs/* w w w.j a v a 2s . c o m*/ */ @Test @NotYetImplemented public void serialization_withJSBackgroundTasks() throws Exception { final String html = "<html><head>\n" + "<script>\n" + " function foo() {\n" + " if (window.name == 'hello') {\n" + " alert('exiting');\n" + " clearInterval(intervalId);\n" + " }\n" + " }\n" + " var intervalId = setInterval(foo, 10);\n" + "</script></head>\n" + "<body></body></html>"; final HtmlPage page = loadPageWithAlerts(html); // verify that 1 background job exists assertEquals(1, page.getEnclosingWindow().getJobManager().getJobCount()); final byte[] bytes = SerializationUtils.serialize(page); page.getWebClient().close(); // deserialize page and verify that 1 background job exists final HtmlPage clonedPage = (HtmlPage) SerializationUtils.deserialize(bytes); assertEquals(1, clonedPage.getEnclosingWindow().getJobManager().getJobCount()); // configure a new CollectingAlertHandler (in fact it has surely already one and we could get and cast it) final List<String> collectedAlerts = Collections.synchronizedList(new ArrayList<String>()); final AlertHandler alertHandler = new CollectingAlertHandler(collectedAlerts); clonedPage.getWebClient().setAlertHandler(alertHandler); // make some change in the page on which background script reacts clonedPage.getEnclosingWindow().setName("hello"); clonedPage.getWebClient().waitForBackgroundJavaScriptStartingBefore(100); assertEquals(0, clonedPage.getEnclosingWindow().getJobManager().getJobCount()); final String[] expectedAlerts = { "exiting" }; assertEquals(expectedAlerts, collectedAlerts); }
From source file:io.pravega.controller.store.stream.ZKStreamMetadataStore.java
@Override public CompletableFuture<Boolean> takeBucketOwnership(int bucket, String processId, Executor executor) { Preconditions.checkArgument(bucket < bucketCount); // try creating an ephemeral node String bucketPath = ZKPaths.makePath(ZKStoreHelper.BUCKET_OWNERSHIP_PATH, String.valueOf(bucket)); return storeHelper.createEphemeralZNode(bucketPath, SerializationUtils.serialize(processId)) .thenCompose(created -> { if (!created) { // Note: data may disappear by the time we do a getData. Let exception be thrown from here // so that caller may retry. return storeHelper.getData(bucketPath).thenApply( data -> (SerializationUtils.deserialize(data.getData())).equals(processId)); } else { return CompletableFuture.completedFuture(true); }/* w w w . j a v a 2s .co m*/ }); }
From source file:com.splicemachine.orc.predicate.SpliceORCPredicate.java
public String serialize() throws IOException { return Base64.encodeBase64String(SerializationUtils.serialize(this)); }
From source file:cc.gospy.core.remote.rabbitmq.RemoteScheduler.java
@Override public void addTask(String executorId, Task task) { if (isSuspend.get()) { return;/* w ww . j a va 2 s . co m*/ } try { channel.basicPublish("", NEW_TASK_QUEUE, MessageProperties.PERSISTENT_BASIC, SerializationUtils.serialize(task)); totalTaskInputCount.incrementAndGet(); } catch (IOException e) { e.printStackTrace(); } }