Hi Bruno-

Since *Session* management is primarily used in the context of Web
applications to manage (persist, replicate, expire, etc)  the *HTTP*
*Session*, you can take a look at the samples I created for the GemFire
support in *Spring Session*, documentation here
<http://docs.spring.io/spring-session/docs/1.3.0.RELEASE/reference/html5/#samples>
[1],
source here
<https://github.com/spring-projects/spring-session/tree/master/samples> [2].

All of these *Spring Session* samples are *Web applications* that are
launched with *Spring Boot* and embed either a GemFire client/server (
ClientCache) or a P2P (peer Cache) to manage the *HTTP* *Session*.

While you can embed a peer GemFire Cache in your Web application
<https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-p2p/src/main/java/sample/Config.java>
[3],
it is more common that your Web application would be a client
<https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java>
[4]
(i.e. ClientCache) to a standalone GemFire Server cluster.

SIDE NOTE: the example configuration in [4] contains additional
configuration
<https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java#L93-L138>
[5]
to coordinate the client and server in an automated integration test
for *Spring
Session* (during the build) and is not needed in your production
application.

If you embed a "peer" Cache your Web application, then that means your Web
application is a member (Server) in the GemFire cluster, which again is not
typical (and not recommended for all UC since your application will be
subject to all the constraints and responsibilities of being a
"member/peer" in a cluster), but is possible.

Now, one last thing... these examples are all *Spring* based, obviously.
However, if you are not using *Spring*, then it is a simple matter to use
similar config in your Web application that uses the GemFire API
<http://data-docs-samples.cfapps.io/docs-gemfire/latest/javadocs/japi/index.html>
[6]
directly to bootstrap a GemFire client or peer cache instance.

In a client/server topology, you might use something like *Gfsh* to launch
members/peers of your cluster.  But, in your Web application, you won't be
using any external tools.  You will be using the GemFire API
<http://data-docs-samples.cfapps.io/docs-gemfire/latest/javadocs/japi/index.html>
[6]
to create a ClientCache using the ClientCacheFactory
<http://data-docs-samples.cfapps.io/docs-gemfire/latest/javadocs/japi/com/gemstone/gemfire/cache/client/ClientCacheFactory.html>
[7].

Of course, *Spring* (and *Spring Data GemFire* in particular) does greatly
simplify all of this for you.

Hope this helps.

Cheers,
John


[1]
http://docs.spring.io/spring-session/docs/1.3.0.RELEASE/reference/html5/#samples
[2] https://github.com/spring-projects/spring-session/tree/master/samples
[3]
https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-p2p/src/main/java/sample/Config.java
[4]
https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java
[5]
https://github.com/spring-projects/spring-session/blob/master/samples/javaconfig/gemfire-clientserver/src/main/java/sample/ClientConfig.java#L93-L138
[6]
http://data-docs-samples.cfapps.io/docs-gemfire/latest/javadocs/japi/index.html
[7]
http://data-docs-samples.cfapps.io/docs-gemfire/latest/javadocs/japi/com/gemstone/gemfire/cache/client/ClientCacheFactory.html


On Fri, Jan 27, 2017 at 9:57 AM, Kirk Lund <[email protected]> wrote:

> Start with the CacheFactory API to create a Cache in your application JVM.
> If you're running a single node then:
>
> Cache cache = new CacheFactory().create();
>
> If you're running a cluster of multiple nodes, then you should start one
> or more Locator processes using GFSH:
>
> gfsh> start locator ...etc...
>
> And then specify the the Locator hostname[port] when you construct your
> application's Cache:
>
> import static org.apache.geode.distributed.ConfigurationProperties.*;
> Cache cache = new CacheFactory().set(LOCATORS, "hostname[10334]").create();
>
>
> On Fri, Jan 27, 2017 at 3:04 AM, Bruno Sinkovic <[email protected]>
> wrote:
>
>> Dear All,
>>
>> Do you know if we can start a Cache in a Web Application, under a Servlet
>> container? If yes, do we need to run a separate process (with gosh for
>> instance) or can the server cache run standalone?
>> Would you have Java API code examples to illustrate this case?
>>
>> Thank you in advance for your prompt support.
>>
>>
>> Kind Regards,
>>
>> *Bruno Sinkovic*
>> Solution Architect
>>
>> [email protected]
>> www.pymma.com
>> M: +41.79.397.5976 <+41%2079%20397%2059%2076>
>>
>>
>>
>>
>>
>


-- 
-John
john.blum10101 (skype)

Reply via email to