Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2008-2015 Aerospike, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.aerospike.session.impl;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import javax.inject.Inject;
import com.aerospike.client.AerospikeClient;
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Key;
import com.aerospike.client.Operation;
import com.aerospike.client.Record;
import com.aerospike.client.policy.GenerationPolicy;
import com.aerospike.client.policy.Policy;
import com.aerospike.client.policy.RecordExistsAction;
import com.aerospike.client.policy.WritePolicy;
import com.aerospike.session.CheckAndSetOperation;
import com.aerospike.session.SessionIDProvider;
import com.aerospike.session.SessionNotFound;
import com.aerospike.session.SessionStore;
import com.aerospike.session.SessionStoreException;
import com.aerospike.session.transcoder.SessionStoreTranscoder;
import com.aerospike.transcoder.TranscodeException;
import com.aerospike.transcoder.Transcoder;
import lombok.extern.slf4j.Slf4j;
/**
* Aerospike implementation of {@link SessionStore}. This implementation on
* startup ensures that all application nodes running the session store share
* the same {@link AerospikeSessionStoreConfig} by reading the configuration
* from the aerospike cluster. The basic requirement is the input configurations
* hostname, port, username, password, namespace, configSet be correct.
*
* @author ashish
*
*/
@Slf4j
public class AerospikeSessionStore implements SessionStore {
private final SessionIDProvider sessionIDProvider;
/**
* The session store configuration.
*/
private final AerospikeSessionStoreConfig config;
/**
* The aerospike client.
*/
private final AerospikeClient client;
/**
* Transcoder for pojos.
*/
private final Transcoder transcoder;
/**
* @param config
* @param client
* @param transcoder
*/
@Inject
public AerospikeSessionStore(SessionIDProvider sessionIDProvider,
AerospikeSessionStoreConfig config,
@SessionStoreAerospikeClient AerospikeClient client,
@SessionStoreTranscoder Transcoder transcoder) {
this.sessionIDProvider = sessionIDProvider;
this.config = config;
this.client = client;
this.transcoder = transcoder;
}
/**
* The method to check whether the value is an instance of primitive
* datatype. If not, we use transcoder to handle pojos.
*
* @param value
* @param depth
* @return
*/
@SuppressWarnings("unchecked")
private Object reformat(Object value, int depth) {
log.debug("Transcoder depth" + depth);
try {
if (value instanceof String || value instanceof Number
|| value instanceof Boolean) {
return value;
} else if (depth == 0 && value instanceof List>) {
List