use of com.tangosol.net.Session in project coherence-spring by coherence-community.
the class CoherenceGrpcClient method buildSession.
/**
* Builds Coherence session.
* @param grpcChannel mMust not be null
* @param coherenceConfigClientProperties must not be null
* @return a Coherence Session
*/
protected Session buildSession(Channel grpcChannel, CoherenceConfigClientProperties coherenceConfigClientProperties) {
Assert.notNull(grpcChannel, "grpcChannel must not be null");
Assert.notNull(coherenceConfigClientProperties, "coherenceConfigClientProperties must not be null");
final GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder(grpcChannel);
if (StringUtils.hasText(coherenceConfigClientProperties.getSessionName())) {
builder.named(coherenceConfigClientProperties.getSessionName());
}
if (StringUtils.hasText(coherenceConfigClientProperties.getScopeName())) {
builder.withScopeName(coherenceConfigClientProperties.getScopeName());
}
final GrpcSessionConfiguration grpcSessionConfiguration = builder.build();
final Optional<Session> optional = Session.create(grpcSessionConfiguration);
return optional.orElseGet(() -> {
throw new IllegalStateException("Unable to create session.");
});
}
use of com.tangosol.net.Session in project coherence-spring by coherence-community.
the class CoherenceConfigDataLoader method getPropertySources.
public List<PropertySource<?>> getPropertySources(CoherenceConfigDataResource resource) {
try (CoherenceGrpcClient coherenceGrpcClient = new CoherenceGrpcClient(resource.getProperties())) {
final List<String> keys = this.buildSourceNames(resource);
final List<PropertySource<?>> composite = new ArrayList<>();
final Session session = coherenceGrpcClient.getCoherenceSession();
for (String propertySourceName : keys) {
final NamedMap<String, Object> configMap = session.getMap(propertySourceName);
final Map<String, Object> results = new HashMap<>(configMap);
final MapPropertySource propertySource = new MapPropertySource(propertySourceName, results);
composite.add(propertySource);
}
return composite;
}
}
use of com.tangosol.net.Session in project coherence-spring by coherence-community.
the class SpringDataAutoConfigurationTests method testInitializationOfSpringDataRepository.
@Test
public void testInitializationOfSpringDataRepository() {
this.contextRunner.withUserConfiguration(ConfigWithEnableCoherenceRepositoriesAnnotation.class).run((context) -> {
final Coherence coherence = context.getBean(Coherence.class);
final Session session = coherence.getSession();
assertThat(context).hasSingleBean(CoherenceServer.class);
assertThat(context).hasSingleBean(SpringDataTaskRepository.class);
final NamedMap<String, Task> tasks = session.getMap("tasks");
assertThat(tasks).hasSize(0);
final SpringDataTaskRepository repository = context.getBean(SpringDataTaskRepository.class);
final Task task = new Task("Write some code.");
repository.save(task);
assertThat(tasks).hasSize(1);
repository.deleteAll();
assertThat(tasks).hasSize(0);
});
}
use of com.tangosol.net.Session in project coherence-spring by coherence-community.
the class CoherenceRepositoryFactory method ensureNamedMap.
/**
* Ensures a {@link NamedMap} is available.
* @return a {@link NamedMap} based on the {@link #mapName}
*/
@SuppressWarnings("rawtypes")
private NamedMap ensureNamedMap() {
if (this.namedMap == null) {
Session session = ensureSession();
this.namedMap = session.getMap(this.mapName);
}
return this.namedMap;
}
use of com.tangosol.net.Session in project coherence-spring by coherence-community.
the class GrpcSessionBeanTests method testBasicGrpcClient.
@Test
@Order(1)
public void testBasicGrpcClient() throws Exception {
final GrpcSessionConfiguration.Builder builder = GrpcSessionConfiguration.builder();
final Session session = Session.create(builder.build()).get();
final Map<String, String> fooMap = session.getMap("fooMap");
fooMap.put("foo", "bar");
final Map<String, String> mapFromCoherence = this.coherence.getSession().getMap("fooMap");
assertEquals("bar", mapFromCoherence.get("foo"));
}
Aggregations