本文整理匯總了Java中com.hazelcast.core.IMap.set方法的典型用法代碼示例。如果您正苦於以下問題:Java IMap.set方法的具體用法?Java IMap.set怎麽用?Java IMap.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.hazelcast.core.IMap
的用法示例。
在下文中一共展示了IMap.set方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setValue
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
public void setValue(String map, String key, String contentType,
int length, final InputStream in) throws IOException
{
verifyBucket(map);
byte type = mapContentType(contentType);
IMap<String, byte[]> m = hazelcast.getMap(map);
int offset = 1;
byte[] data = new byte[length + offset];
data[0] = type;
int num;
while ((num = in.read(data, offset, length)) > 0) {
offset += num;
if (offset >= data.length) {
break;
}
}
m.set(key, data);
}
示例2: addTicket
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Override
public void addTicket(final Ticket ticket) {
final long ttl = ticket.getExpirationPolicy().getTimeToLive();
if (ttl < 0) {
throw new IllegalArgumentException("The expiration policy of ticket "
+ ticket.getId() + "is set to use a negative ttl");
}
LOGGER.debug("Adding ticket [{}] with ttl [{}s]", ticket.getId(), ttl);
final Ticket encTicket = encodeTicket(ticket);
final TicketDefinition metadata = this.ticketCatalog.find(ticket);
final IMap<String, Ticket> ticketMap = getTicketMapInstanceByMetadata(metadata);
ticketMap.set(encTicket.getId(), encTicket, ttl, TimeUnit.SECONDS);
LOGGER.debug("Added ticket [{}] with ttl [{}s]", encTicket.getId(), ttl);
}
示例3: handleRequest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void handleRequest(HttpServerExchange exchange) throws Exception {
Map<String, Object> body = (Map)exchange.getAttachment(BodyHandler.REQUEST_BODY);
User user = Config.getInstance().getMapper().convertValue(body, User.class);
String userId = user.getUserId();
IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
User u = users.get(userId);
if(u == null) {
Status status = new Status(USER_NOT_FOUND, userId);
exchange.setStatusCode(status.getStatusCode());
exchange.getResponseSender().send(status.toString());
} else {
// as password is not in the return value, chances are password is not in the user object
user.setPassword(u.getPassword());
user.setUpdateDt(new Date(System.currentTimeMillis()));
users.set(userId, user);
}
}
示例4: simpleTest
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@Test
public void simpleTest() throws Exception {
final IMap<Integer, String> testMapFromMember = member.getMap("testMap");
testMapFromMember.set(1, "test1");
final IMap<Integer, String> testMap = client.getMap("testMap");
final String value = testMap.get(1);
assertEquals("member puts, client gets", value, "test1");
}
示例5: handlePassword
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
private Map<String, Object> handlePassword(HttpServerExchange exchange, String userId, char[] password, String scope, Map<String, Object> formMap) throws ApiException {
if(logger.isDebugEnabled()) logger.debug("userId = " + userId + " scope = " + scope);
Client client = authenticateClient(exchange, formMap);
if(client != null) {
// authenticate user with credentials
if(userId != null) {
if(password != null) {
IMap<String, User> users = CacheStartupHookProvider.hz.getMap("users");
User user = users.get(userId);
// match password
try {
if(HashUtil.validatePassword(password, user.getPassword())) {
Arrays.fill(password, ' ');
// make sure that client is trusted
if(client.getClientType() == Client.ClientTypeEnum.TRUSTED) {
if(scope == null) {
scope = client.getScope(); // use the default scope defined in client if scope is not passed in
} else {
// make sure scope is in scope defined in client.
if(!matchScope(scope, client.getScope())) {
throw new ApiException(new Status(MISMATCH_SCOPE, scope, client.getScope()));
}
}
String jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, user.getUserType().toString(), null));
// generate a refresh token and associate it with userId and clientId
String refreshToken = UUID.randomUUID().toString();
RefreshToken token = new RefreshToken();
token.setRefreshToken(refreshToken);
token.setUserId(userId);
token.setClientId(client.getClientId());
token.setScope(scope);
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.set(refreshToken, token);
Map<String, Object> resMap = new HashMap<>();
resMap.put("access_token", jwt);
resMap.put("token_type", "bearer");
resMap.put("expires_in", config.getExpiredInMinutes()*60);
resMap.put("refresh_token", refreshToken);
return resMap;
} else {
throw new ApiException(new Status(NOT_TRUSTED_CLIENT));
}
} else {
throw new ApiException(new Status(INCORRECT_PASSWORD));
}
} catch (NoSuchAlgorithmException | InvalidKeySpecException | JoseException e) {
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
}
} else {
throw new ApiException(new Status(PASSWORD_REQUIRED));
}
} else {
throw new ApiException(new Status(USERNAME_REQUIRED));
}
}
return new HashMap<>(); // return an empty hash map. this is actually not reachable at all.
}
示例6: handleClientAuthenticatedUser
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
/**
* This grant type is custom grant type that assume client has already authenticated the user and only send the user info
* to the authorization server to get the access token. The token is similar with authorization code token. All extra info
* from the formMap will be put into the token as custom claim.
*
* Also, only
*
* @param exchange
* @param formMap
* @return
* @throws ApiException
*/
@SuppressWarnings("unchecked")
private Map<String, Object> handleClientAuthenticatedUser(HttpServerExchange exchange, Map<String, Object> formMap) throws ApiException {
if(logger.isDebugEnabled()) logger.debug("client authenticated user grant formMap = " + formMap);
Client client = authenticateClient(exchange, formMap);
if(client != null) {
// make sure that client is trusted
if(Client.ClientTypeEnum.TRUSTED == client.getClientType()) {
String scope = (String)formMap.remove("scope");
if(scope == null) {
scope = client.getScope(); // use the default scope defined in client if scope is not passed in
} else {
// make sure scope is in scope defined in client.
if(!matchScope(scope, client.getScope())) {
throw new ApiException(new Status(MISMATCH_SCOPE, scope, client.getScope()));
}
}
// make sure that userId and userType are passed in the formMap.
String userId = (String)formMap.remove("userId");
if(userId == null) {
throw new ApiException(new Status(USER_ID_REQUIRED_FOR_CLIENT_AUTHENTICATED_USER_GRANT_TYPE));
}
String userType = (String)formMap.remove("userType");
if(userType == null) {
throw new ApiException(new Status(USER_TYPE_REQUIRED_FOR_CLIENT_AUTHENTICATED_USER_GRANT_TYPE));
}
String jwt;
try {
jwt = JwtHelper.getJwt(mockAcClaims(client.getClientId(), scope, userId, userType, formMap));
} catch (Exception e) {
throw new ApiException(new Status(GENERIC_EXCEPTION, e.getMessage()));
}
// generate a refresh token and associate it with userId and clientId
String refreshToken = UUID.randomUUID().toString();
RefreshToken token = new RefreshToken();
token.setRefreshToken(refreshToken);
token.setUserId(userId);
token.setClientId(client.getClientId());
token.setScope(scope);
IMap<String, RefreshToken> tokens = CacheStartupHookProvider.hz.getMap("tokens");
tokens.set(refreshToken, token);
Map<String, Object> resMap = new HashMap<>();
resMap.put("access_token", jwt);
resMap.put("token_type", "bearer");
resMap.put("expires_in", config.getExpiredInMinutes()*60);
resMap.put("refresh_token", refreshToken);
return resMap;
} else {
// not trusted client, this is not allowed.
throw new ApiException(new Status(NOT_TRUSTED_CLIENT));
}
}
return new HashMap<>(); // return an empty hash map. this is actually not reachable at all.
}
示例7: setInstanceValue
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
/**
* Puts a value to a Map, which is specific to this instance
* @param key
* @param value
*/
public <K, V> void setInstanceValue(K key, V value) {
IMap<K, V> cached = hzInstance.getMap(instanceMapName());
cached.set(key, value);
}
示例8: setInstanceCachedValue
import com.hazelcast.core.IMap; //導入方法依賴的package包/類
/**
* Puts a cached value to a Map, which is specific to this instance
* @param map
* @param value
*/
public void setInstanceCachedValue(String map, DataSerializable value) {
IMap<String, DataSerializable> cached = hzInstance.getMap(map);
cached.set(hzInstance.getInstanceId(), value);
}