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

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

Introduction

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

Prototype

public static Object deserialize(byte[] objectData) 

Source Link

Document

Deserializes a single Object from an array of bytes.

Usage

From source file:io.pravega.common.cluster.zkImpl.ClusterZKImpl.java

private PathChildrenCacheListener pathChildrenCacheListener(final ClusterListener listener) {
    return (client, event) -> {
        log.debug("Event {} generated on cluster", event);
        switch (event.getType()) {
        case CHILD_ADDED:
            log.info("Node {} added to cluster", getServerName(event));
            listener.onEvent(HOST_ADDED, (Host) SerializationUtils.deserialize(event.getData().getData()));
            break;
        case CHILD_REMOVED:
            log.info("Node {} removed from cluster", getServerName(event));
            listener.onEvent(HOST_REMOVED, (Host) SerializationUtils.deserialize(event.getData().getData()));
            break;
        case CHILD_UPDATED:
            log.warn("Invalid usage: Node {} updated externally for cluster", getServerName(event));
            break;
        case CONNECTION_LOST:
            log.error("Connection lost with Zookeeper");
            listener.onEvent(ERROR, null);
            break;
        //$CASES-OMITTED$
        default:// w w  w. j av a2  s .c o  m
            log.warn("Received unknown event {}", event.getType());
        }
    };
}

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

/**
 * Method to get Service Status in its raw state i.e. without any check or update.
 * //from  www . j ava  2 s .  c  om
 * @param technology
 * @return
 */
@Transient
public HashMap<String, Map<String, Boolean>> getTechnologyGroupedRawServiceStatus(String technology) {
    HashMap<String, Map<String, Boolean>> techServiceMap = new HashMap<String, Map<String, Boolean>>();
    HashMap<String, Map<String, Boolean>> serviceMap = new HashMap<String, Map<String, Boolean>>();
    byte[] techBytes = getTechnologyServiceBytes();
    if (techBytes == null) {
        return serviceMap;
    }

    // deserializing the data.
    techServiceMap = (HashMap<String, Map<String, Boolean>>) SerializationUtils.deserialize(techBytes);

    if (technology != null) {
        serviceMap.put(technology, techServiceMap.get(technology));
    } else {
        serviceMap.putAll(techServiceMap);
    }

    /*      
          if (technology == null) {
             Map agentStatus = new HashMap<String, Boolean>();
             agentStatus.put(Constant.Component.Name.AGENT, isAgentDown());
             serviceMap.put(Constant.Component.Name.AGENT, agentStatus);
          }
    */

    // return service status.
    return serviceMap;
}

From source file:mitm.common.hibernate.CertificateArrayUserType.java

@Override
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
        throws HibernateException, SQLException {
    Certificate[] certificates = null;

    byte[] bytes = rs.getBytes(names[CERTIFICATE_ARRAY_COLUMN]);

    if (!rs.wasNull() && bytes != null) {
        Object deserialized = SerializationUtils.deserialize(bytes);

        if (!(deserialized instanceof LinkedList)) {
            throw new IllegalArgumentException("Object is not a LinkedList.");
        }/* www. jav a  2  s.  com*/

        try {
            @SuppressWarnings("unchecked")
            List<EncodedCertificate> encodedCertificates = (LinkedList<EncodedCertificate>) deserialized;

            certificates = new Certificate[encodedCertificates.size()];

            for (int i = 0; i < certificates.length; i++) {
                certificates[i] = encodedCertificates.get(i).getCertificate();
            }
        } catch (CertificateException e) {
            throw new HibernateException(e);
        } catch (NoSuchProviderException e) {
            throw new HibernateException(e);
        }
    }

    return certificates;
}

From source file:com.janrain.backplane2.server.dao.redis.RedisBackplaneMessageDAO.java

@Override
public void retrieveMessagesPerScope(@NotNull MessagesResponse bpResponse, @NotNull Token token)
        throws BackplaneServerException {
    final Scope scope = token.getScope();
    final boolean isAnonymous = token.getType() == GrantType.ANONYMOUS;
    Jedis jedis = null;//from   w  w w.j  av  a  2 s . c om
    try {
        jedis = Redis.getInstance().getReadJedis();
        Transaction t = jedis.multi();
        List<String> unions = new ArrayList<String>();

        Set<String> channelScopes = scope.getScopeFieldValues(BackplaneMessage.Field.CHANNEL);
        if (channelScopes != null) {
            String channelUnion = "scope_req_" + ChannelUtil.randomString(10);
            unions.add(channelUnion);
            for (String channel : channelScopes) {
                t.zunionstore(channelUnion.getBytes(), new ZParams() {
                    {
                        aggregate(Aggregate.MAX);
                    }
                }, channelUnion.getBytes(), getChannelKey(channel));
            }
        }
        Set<String> busScopes = scope.getScopeFieldValues(BackplaneMessage.Field.BUS);
        // don't try to get bus messages for anonymous tokens (since it's supposed to be only for a specific channel)
        if (busScopes != null && !isAnonymous) {
            String busUnion = "scope_req_" + ChannelUtil.randomString(10);
            unions.add(busUnion);
            for (String bus : busScopes) {
                t.zunionstore(busUnion.getBytes(), new ZParams() {
                    {
                        aggregate(Aggregate.MAX);
                    }
                }, busUnion.getBytes(), getBusKey(bus));
            }
        }
        String channelBusIntersection = null;
        for (String union : unions) {
            if (channelBusIntersection == null) {
                channelBusIntersection = union;
            } else {
                t.zinterstore(channelBusIntersection.getBytes(), new ZParams() {
                    {
                        aggregate(Aggregate.MAX);
                    }
                }, channelBusIntersection.getBytes(), union.getBytes());
            }
        }

        Response<Set<byte[]>> lastResponse = t.zrange(V2_MESSAGES.getBytes(), -1, -1);
        List<BackplaneMessage> messages = new ArrayList<BackplaneMessage>();

        if (channelBusIntersection != null) {
            Date lastMessageDate = BackplaneMessage.getDateFromId(bpResponse.getLastMessageId());
            long lastMessageTime = lastMessageDate == null ? 0 : lastMessageDate.getTime();
            Response<Set<String>> busChannelMessageIds = t.zrangeByScore(channelBusIntersection,
                    lastMessageTime + 1, Double.MAX_VALUE);
            for (String union : unions)
                t.del(union);
            t.exec();
            if (!busChannelMessageIds.get().isEmpty()) {
                List<byte[]> idBytes = new ArrayList<byte[]>();
                for (String msgId : busChannelMessageIds.get()) {
                    idBytes.add(getKey(msgId));
                }
                for (byte[] messageBytes : jedis.mget(idBytes.toArray(new byte[idBytes.size()][]))) {
                    if (messageBytes != null)
                        messages.add((BackplaneMessage) SerializationUtils.deserialize(messageBytes));
                }

            }
        } else {
            t.exec();
        }

        if (!messages.isEmpty()) {
            filterMessagesPerScope(messages, scope, bpResponse);
        } else {
            Set<byte[]> lastBytes = lastResponse.get();
            if (lastBytes.isEmpty()) {
                bpResponse.setLastMessageId("");
            } else {
                String lastMessageId = new String(lastBytes.iterator().next()).split(" ")[2];
                bpResponse.setLastMessageId(lastMessageId);
            }
        }
    } catch (Exception e) {
        logger.error(e.getMessage(), e);
        throw new BackplaneServerException(e.getMessage(), e);
    } finally {
        Redis.getInstance().releaseToPool(jedis);
    }
}

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

@Override
public CompletableFuture<Boolean> updateState(final State state) {
    return getStateData().thenCompose(currState -> {
        if (State.isTransitionAllowed((State) SerializationUtils.deserialize(currState.getData()), state)) {
            return setStateData(new Data<>(SerializationUtils.serialize(state), currState.getVersion()))
                    .thenApply(x -> true);
        } else {//from   w ww. ja  va  2s.  co m
            return FutureHelpers.failedFuture(StoreException.create(StoreException.Type.OPERATION_NOT_ALLOWED,
                    "Stream: " + getName() + " State: " + state.name()));
        }
    });
}

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

/**
 * Gets the node config obj./*from w  w w.ja  va2 s  . c  o m*/
 * 
 * @return the object
 */
@Transient
@JsonIgnore
public NodeConfig getNodeConfig() {
    if (getConfBytes() == null) {
        return null;
    }
    return (NodeConfig) SerializationUtils.deserialize(getConfBytes());
}

From source file:com.janrain.backplane.server.dao.redis.RedisBackplaneMessageDAO.java

/**
 * Fetch a list (possibly empty) of backplane messages that exist on the channel
 * and return them in order by message id
 * @param channel//from w w w .jav  a  2 s.c  o  m
 * @return
 */

public List<BackplaneMessage> getMessagesByChannel(String bus, String channel, String since, String sticky)
        throws SimpleDBException, BackplaneServerException {

    Jedis jedis = null;

    try {

        jedis = Redis.getInstance().getReadJedis();

        double sinceInMs = 0;
        if (StringUtils.isNotBlank(since)) {
            sinceInMs = BackplaneMessage.getDateFromId(since).getTime();
        }

        // every message has a unique timestamp - which serves as a key for indexing
        List<byte[]> messageIdBytes = jedis.lrange(getChannelKey(channel), 0, -1);
        List<BackplaneMessage> messages = new ArrayList<BackplaneMessage>();

        if (!messageIdBytes.isEmpty()) {
            int i = 0;
            for (byte[] key : messageIdBytes) {
                messageIdBytes.set(i++, getKey(new String(key)));
            }

            List<byte[]> responses = jedis.mget(messageIdBytes.toArray(new byte[messageIdBytes.size()][]));
            for (byte[] response : responses) {
                if (response != null) {
                    messages.add((BackplaneMessage) SerializationUtils.deserialize(response));
                }
            }
        }

        filterAndSort(messages, since, sticky);
        return messages;

    } catch (JedisConnectionException jce) {
        logger.warn("connection broken on bus " + bus + " and channel " + channel);
        Redis.getInstance().releaseBrokenResourceToPool(jedis);
        jedis = null;
        throw new BackplaneServerException(jce.getMessage(), jce);
    } catch (Exception e) {
        logger.error("Exception on bus " + bus + " and channel " + channel, e);
        throw new BackplaneServerException(e.getMessage(), e);
    } finally {
        Redis.getInstance().releaseToPool(jedis);
    }

}

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

@Override
public CompletableFuture<State> getState() {
    return getStateData().thenApply(x -> (State) SerializationUtils.deserialize(x.getData()));
}

From source file:mitm.application.djigzo.james.mailets.MailAttributes.java

private void initSerializedAttributes() {
    serializedAttributes = new HashMap<String, Serializable>();

    String[] values = getValues(getConfiguration().getChildren(Parameter.SERIALIZED.name));

    if (values != null) {
        for (String value : values) {
            value = StringUtils.trimToNull(value);

            if (value == null) {
                continue;
            }/*from  w w w .  j  a v  a2 s. com*/

            String[] nameValue = parseNameValue(value);

            if (nameValue == null) {
                throw new IllegalArgumentException(value + " is not a valid name value pair.");
            }

            Serializable serialized = (Serializable) SerializationUtils
                    .deserialize(Base64Utils.decode(nameValue[1]));

            serializedAttributes.put(nameValue[0], serialized);
        }
    }
}

From source file:com.moz.fiji.mapreduce.kvstore.lib.InMemoryMapKeyValueStore.java

@SuppressWarnings("unchecked")
@Override//  ww w  .  ja  v a2 s . c o  m
public void initFromConf(KeyValueStoreConfiguration conf) throws IOException {
    Preconditions.checkState(!mOpened, "Cannot reinitialize; already opened.");

    mMap = (HashMap<K, V>) SerializationUtils.deserialize(Base64.decodeBase64(conf.get(CONF_MAP)));
}