11 Replies Latest reply on Feb 9, 2016 10:49 AM by Tomaz Cerar

    How to create named cache through hotrod client?

    Udit Mishra Novice

      I am pretty new to the infinispan platform. I am using the client server model of infinispan. My cache server is going to be centralized for different clients. Each client is a web application (which is an instance of a product) and we are using hotrod client as it is de facto for java applications. Now, I do not want the keys of different clients to collide, as it will be of same name.

      Is there any option to create named cache from hotrod client?? Lets say client A, says create a named cache "ClientA" and put all my keys into that, and Client B asks for a named cache "ClientB", so even if they both retrieve a stored key say "specialKey" they will never get each other's data.

      One way of doing it is hard coding the cache entry in <cache-container> element. But, I do not want to do that, as my clients can be added at anytime. I want it to work it from the client side, that too at runtime. Shouldn't it be flexible??

      If it is not possible, then what can I do alternatively?? as my client is going to be using hotrod only. I do not think hard coding cache name in the server's configuration file is a good idea. Its nearly impossible to manage when new clients are added.

        • 1. Re: How to create named cache through hotrod client?
          Tristan Tarrant Master

          We don't yet have a fully-fledged client for doing this (but we will be adding it).

          The supported way to do this is by using the management interface for the server: either the web console or the CLI.

          Supposing you are using domain mode, here's how you can create a new cache based on an existing named configuration:

           

          $ ./bin/ispn-cli.sh
          You are disconnected at the moment. Type 'connect' to connect to the server or 'help' for the list of supported commands.
          [disconnected /] connect
          [domain@localhost:9990 /] cd profile=clustered/subsystem=datagrid-infinispan/cache-container=clustered
          [domain@localhost:9990 cache-container=clustered] ./distributed-cache=mycache:add(configuration=default)
          {
              "outcome" => "success",
              "result" => undefined,
              "server-groups" => {"main-server-group" => {"host" => {"master" => {
                  "server-one" => {"response" => {"outcome" => "success"}},
                  "server-two" => {"response" => {"outcome" => "success"}}
              }}}}
          }
          

          The above commands has created a new distributed cache named 'mycache' using the named 'default' configuration on all nodes.

          In standalone mode, the initial path is slightly different (the subsystem is at the root, not under the profile), but you will have to invoke the operation on all nodes.

          1 of 1 people found this helpful
          • 2. Re: How to create named cache through hotrod client?
            Udit Mishra Novice

            Hello nadirx ,

             

            I have followed the same steps, and yes it worked perfectly. I could see the new cache in the management console. Also, I saw a console message -

             

            [Server:CollaborateServerOne] 13:15:38,931 INFO  [org.jboss.as.clustering.infinispan] (MSC service thread 1-8) DGISPN0001: Started uditcache cache from CollaborateCacheContainer container

             

            However, the domain.xml file which was there in my editor, did not get refresh. Even after closing and opening it again, did not make any change into it. That led me to the other suspicion that will that cache be available when I will restart my server. Then I restarted my server and it was not there. I'am afraid if it works like this or am I missing something?

            • 3. Re: How to create named cache through hotrod client?
              Tristan Tarrant Master

              Changes made to the domain configuration are persisted as soon as they are committed successfully. I've just tried locally it and it worked.

              • 4. Re: How to create named cache through hotrod client?
                Udit Mishra Novice

                Alright, but its not working in my case. Till the server was up, I could do client operations with that newly created cache, but as soon as I restarted it, it got wiped out. I assume there is something wrong. Could you please tell me what should I do? Or what could be the possible reason behind this unexpected behavior?

                • 6. Re: How to create named cache through hotrod client?
                  Tristan Tarrant Master

                  Windows has weird file locking: if you keep the file open in the editor it probably blocked the server from writing back the changes. Let me verify with ctomc who works on WildFly and is an expert Windows user, who can confirm or not my hunch.

                  • 7. Re: How to create named cache through hotrod client?
                    Udit Mishra Novice

                    I closed the editor and did the above mentioned steps. but it says failed along with the message that - System boot is in process; execution of remote management operation is currently not available.

                    • 8. Re: How to create named cache through hotrod client?
                      Tristan Tarrant Master

                      All of the servers in the server group must be in their RUNNING mode.

                      • 9. Re: How to create named cache through hotrod client?
                        Udit Mishra Novice

                        nadirx I restarted everything. It gave me success message, but the main problem is still there, cache which was created does not persist.I opened the domain.xml file after shutting down the server, but no information was written in that file under <cache-container> element, which was expected. I hope if ctomc can help me out.

                        • 10. Re: How to create named cache through hotrod client?
                          Galder Zamarreño Master

                          We have also created a remote JSR-107 implementation which uses underneath the Hot Rod client. One of the requirements of JCache is the ability of create caches remotely. We implemented this feature taking advantage of the remote JBoss/Wildfly management client. This class contains the logic to achieve that.

                           

                          Also, I don't know about the persistence issues that you're having.

                          • 11. Re: How to create named cache through hotrod client?
                            Tomaz Cerar Master

                            Udit Mishra wrote:

                             

                            NadirX I restarted everything. It gave me success message, but the main problem is still there, cache which was created does not persist.I opened the domain.xml file after shutting down the server, but no information was written in that file under <cache-container> element, which was expected. I hope if ctomc can help me out.

                            Hey guys, sorry for late reply on this.

                             

                            Windows file locking shouldn't have anything to do with what you are seeing, if problem would be file lock because of having said file open in some broken editor (that does exclusive file open) you should see some error / warning in console.log/server.log of domain controller.

                             

                            maybe try with different file editor (notepad++ for example) if that would help. otherwise check if some antivirus software isn't preventing something.