Example usage for org.apache.commons.lang SerializationUtils serialize

List of usage examples for org.apache.commons.lang SerializationUtils serialize

Introduction

In this page you can find the example usage for org.apache.commons.lang SerializationUtils serialize.

Prototype

public static byte[] serialize(Serializable obj) 

Source Link

Document

Serializes an Object to a byte array for storage/serialization.

Usage

From source file:io.pravega.controller.store.stream.ZKStream.java

@Override
public CompletableFuture<Void> createConfigurationIfAbsent(final StreamConfiguration configuration) {
    return store.createZNodeIfNotExist(configurationPath, SerializationUtils.serialize(configuration))
            .thenApply(x -> cache.invalidateCache(configurationPath));
}

From source file:com.impetus.ankush.common.domain.NodeMonitoring.java

/**
 * Sets the technology data./*  w ww . j  a  v  a 2  s .c o m*/
 * 
 * @param technologyData
 *            the technologyData to set
 */
public void setTechnologyData(HashMap<String, TechnologyData> technologiesData) {
    setTechnologyDataBytes(SerializationUtils.serialize(technologiesData));
}

From source file:io.pravega.controller.store.stream.ZKStream.java

@Override
public CompletableFuture<Void> createStateIfAbsent(final State state) {
    return store.createZNodeIfNotExist(statePath, SerializationUtils.serialize(state))
            .thenApply(x -> cache.invalidateCache(statePath));
}

From source file:com.nflabs.shiro.cache.zookeeper.ZookeeperCache.java

private void persistData(K key, V value) {
    try {//from  w  ww  . ja v a 2 s .co  m
        zookeeperClient.setData(getDataPath(key), SerializationUtils.serialize((Serializable) value), -1);
    } catch (KeeperException | InterruptedException e) {
        //throw new CacheException(e);
        LOG.error("Error: {}", e.getMessage());
    }
}

From source file:co.cask.cdap.internal.app.runtime.schedule.store.DatasetBasedTimeScheduleStore.java

private void persistTrigger(Table table, OperableTrigger trigger, Trigger.TriggerState state) throws Exception {

    byte[][] cols = new byte[1][];
    byte[][] values = new byte[1][];

    cols[0] = Bytes.toBytes(trigger.getKey().getName());
    values[0] = SerializationUtils.serialize(new TriggerStatus(trigger, state));
    table.put(TRIGGER_KEY, cols, values);
}

From source file:co.cask.cdap.internal.app.runtime.schedule.DataSetBasedScheduleStore.java

private void persistTrigger(OrderedTable table, OperableTrigger trigger, Trigger.TriggerState state)
        throws Exception {

    byte[][] cols = new byte[1][];
    byte[][] values = new byte[1][];

    cols[0] = Bytes.toBytes(trigger.getKey().getName());
    values[0] = SerializationUtils.serialize(new TriggerStatus(trigger, state));
    table.put(TRIGGER_KEY, cols, values);
}

From source file:io.pravega.service.server.host.ZKSegmentContainerMonitorTest.java

@Test
public void testRetryOnStartFailures() throws Exception {
    @Cleanup//www .  j av a  2  s . co m
    CuratorFramework zkClient = startClient();
    initializeHostContainerMapping(zkClient);

    SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
    @Cleanup
    ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
    segMonitor.initialize(Duration.ofSeconds(1));

    // Simulate a container that fails to start.
    CompletableFuture<ContainerHandle> failedFuture = FutureHelpers.failedFuture(new RuntimeException());
    when(containerRegistry.startContainer(eq(2), any())).thenReturn(failedFuture);

    // Use ZK to send that information to the Container Manager.
    HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
    currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));

    // Verify that it does not start.
    verify(containerRegistry, timeout(10000).atLeastOnce()).startContainer(eq(2), any());
    assertEquals(0, segMonitor.getRegisteredContainers().size());

    // Now simulate success for the same container.
    ContainerHandle containerHandle = mock(ContainerHandle.class);
    when(containerHandle.getContainerId()).thenReturn(2);
    when(containerRegistry.startContainer(eq(2), any()))
            .thenReturn(CompletableFuture.completedFuture(containerHandle));

    // Verify that it retries and starts the same container again.
    verify(containerRegistry, timeout(10000).atLeastOnce()).startContainer(eq(2), any());
    Thread.sleep(2000);
    assertEquals(1, segMonitor.getRegisteredContainers().size());
}

From source file:io.pravega.segmentstore.server.host.ZKSegmentContainerMonitorTest.java

@Test
public void testRetryOnStartFailures() throws Exception {
    @Cleanup//from   w w  w  .  j  a  va  2 s . c  om
    CuratorFramework zkClient = startClient();
    initializeHostContainerMapping(zkClient);

    SegmentContainerRegistry containerRegistry = createMockContainerRegistry();
    @Cleanup
    ZKSegmentContainerMonitor segMonitor = createContainerMonitor(containerRegistry, zkClient);
    segMonitor.initialize(Duration.ofSeconds(1));

    // Simulate a container that fails to start.
    CompletableFuture<ContainerHandle> failedFuture = FutureHelpers.failedFuture(new RuntimeException());
    when(containerRegistry.startContainer(eq(2), any())).thenReturn(failedFuture);

    // Use ZK to send that information to the Container Manager.
    HashMap<Host, Set<Integer>> currentData = deserialize(zkClient, PATH);
    currentData.put(PRAVEGA_SERVICE_ENDPOINT, Collections.singleton(2));
    zkClient.setData().forPath(PATH, SerializationUtils.serialize(currentData));

    // Verify that it does not start.
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
    assertEquals(0, segMonitor.getRegisteredContainers().size());

    // Now simulate success for the same container.
    ContainerHandle containerHandle = mock(ContainerHandle.class);
    when(containerHandle.getContainerId()).thenReturn(2);
    when(containerRegistry.startContainer(eq(2), any()))
            .thenReturn(CompletableFuture.completedFuture(containerHandle));

    // Verify that it retries and starts the same container again.
    verify(containerRegistry, timeout(1000).atLeastOnce()).startContainer(eq(2), any());
    Thread.sleep(2000);
    assertEquals(1, segMonitor.getRegisteredContainers().size());
}

From source file:com.impetus.ankush.common.domain.NodeMonitoring.java

/**
 * Method to set graph view data./*  www. j a v  a2s .c o m*/
 * 
 * @param graphViewData
 */
public void setGraphViewData(HashMap graphViewData) {
    // if graphViewData is not null.
    if (graphViewData != null) {
        this.graphView = SerializationUtils.serialize(graphViewData);
    }
}

From source file:com.impetus.ankush.common.domain.Cluster.java

/**
 * Sets the alert conf./*w w w  . j a v  a 2s  .c o  m*/
 * 
 * @param object
 *            the object to set
 */
@Transient
public void setAlertConf(AlertsConf object) {
    this.setAnConfBytes(SerializationUtils.serialize(object));
}