You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by minisoft_rm <mi...@hotmail.com> on 2016/05/05 02:33:59 UTC

How to start and use ignite in Tomcat

Dear all,
 i searched a number of topics here. but still don't know how to start and
use ignite (in client mode) from Tomcat.... you know, I launched the
standalone ignite as server node. 

my code in tomcat web app like this:"

this.ignite =
Ignition.start(ClientConfigurationFactory.createConfiguration());

			Class.forName("org.apache.ignite.IgniteJdbcDriver");
			this.conn = DriverManager
	
.getConnection("jdbc:ignite:cfg://cache=b2c_accCache@file:///Users/i306576/Documents/ignite/apache-ignite-fabric-1.5.0.final-bin/examples/config/ignite-jdbc.xml");
			this.cartCacher = new CartCacher();
			this.ic = ignite.cache("b2c_accCache");

"

the console log show some error mes I don't understand..."
Caused by: class org.apache.ignite.IgniteCheckedException: Ignite instance
with this name has already been started: b2c_acc
"

:-(  the thing is.... this kind of client mode is ok without Tomcat...

please help~~




--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-start-and-use-ignite-in-Tomcat-tp4776.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to start and use ignite in Tomcat

Posted by Denis Magda <dm...@gridgain.com>.
Hi, 

Yes, you can start an Ignite client node inside of your application container and communicate with the cluster through it.

> however, the exception is about "class org.apache.ignite.IgniteException:
> Ignite instance with this name has already been started: b2c_acc"…

This exception happens in cases when you are starting several Ignite nodes with the same name inside of a single JVM process. 
If you need to have several Ignite instances inside of a single JVM process then you have to set a unique name for every node using IgniteConfiguration.setGridName. If it’s not your case then you should look through your code finding a place that start the node instance one more time.

—
Denis

> On May 6, 2016, at 2:04 PM, minisoft_rm <mi...@hotmail.com> wrote:
> 
> Hello experts~~~
>  my goal is to use ignite(in standalone server style) from tomcat webapp.
>  And I am trying to start ignite client in web app owned logic(programming
> it, not by ServletContextListenerStartup), does it work?  
> 
> in my project, I want to hide one table (table in mysql DB) by putting
> ignite layer on above of it.
> 
> indeed, ignite doesn't support insert/update/delete so far. So I did some
> coding to translate them to put operations....~~~~
> 
> however, the exception is about "class org.apache.ignite.IgniteException:
> Ignite instance with this name has already been started: b2c_acc"...   what
> is the root cause of it? might it be only one ignite instance there per
> jvm?.... and where/who start ignite several times?....
> 
> 
> 
> --
> View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-start-and-use-ignite-in-Tomcat-tp4776p4822.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.


Re: How to start and use ignite in Tomcat

Posted by minisoft_rm <mi...@hotmail.com>.
Hello experts~~~
  my goal is to use ignite(in standalone server style) from tomcat webapp.
  And I am trying to start ignite client in web app owned logic(programming
it, not by ServletContextListenerStartup), does it work?  

in my project, I want to hide one table (table in mysql DB) by putting
ignite layer on above of it.

indeed, ignite doesn't support insert/update/delete so far. So I did some
coding to translate them to put operations....~~~~

 however, the exception is about "class org.apache.ignite.IgniteException:
Ignite instance with this name has already been started: b2c_acc"...   what
is the root cause of it? might it be only one ignite instance there per
jvm?.... and where/who start ignite several times?....



--
View this message in context: http://apache-ignite-users.70518.x6.nabble.com/How-to-start-and-use-ignite-in-Tomcat-tp4776p4822.html
Sent from the Apache Ignite Users mailing list archive at Nabble.com.

Re: How to start and use ignite in Tomcat

Posted by Alexei Scherbakov <al...@gmail.com>.
Hi,

Please clarify what are you trying to achieve?
From logs I see the Ignite grid instance tries to start several times.
Please check the ServletContextListenerStartup class
for example how to correctly start Ignite in the servlet environment:

https://github.com/apache/ignite/blob/master/modules/web/src/main/java/org/apache/ignite/startup/servlet/ServletContextListenerStartup.java




2016-05-05 17:24 GMT+03:00 Andrey Gura <ag...@gridgain.com>:

> Hi,
>
> In order to start clint node you should just execute code like this:
>
> Ignition.setClientMode(true);
> Ignition.start();
>
> In this case client node with default configuration will be started. Of
> course you can provide own IgniteConfiguration programatically:
>
> IgniteConfiguration cfg = new IgniteConfiguration();
> cfg.setClientMode(true);
> // ... other settings
> Ignition.start(cfg);
>
> or using Spring configuration files:
>
> <beans xmlns="http://www.springframework.org/schema/beans"
>        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>        xsi:schemaLocation="http://www.springframework.org/schema/beans
>
> http://www.springframework.org/schema/beans/spring-beans.xsd">
>
>     <bean id="ignite.cfg"
> class="org.apache.ignite.configuration.IgniteConfiguration">
>
>         <property name="clientMode" value="true"/>
>
>         <!-- Explicitly configure TCP discovery SPI to provide list of
> initial nodes. -->
>         <property name="discoverySpi">
>             <bean
> class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
>                 <property name="ipFinder">
>                     <!--
>                         Ignite provides several options for automatic
> discovery that can be used
>                         instead os static IP based discovery. For
> information on all options refer
>                         to our documentation:
> http://apacheignite.readme.io/docs/cluster-config
>                     -->
>                     <!-- Uncomment static IP finder to enable static-based
> discovery of initial nodes. -->
>                     <!--<bean
> class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
>                     <bean
> class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
>                         <property name="addresses">
>                             <list>
>                                 <!-- In distributed environment, replace
> with actual host IP address. -->
>                                 <value>127.0.0.1:47500..47509</value>
>                             </list>
>                         </property>
>                     </bean>
>                 </property>
>             </bean>
>         </property>
>     </bean>
>
> </beans>
>
>
> If you want use JDBC drievr for connection to Ignite cluster there is no
> need to create any client nodes.
>
>
> On Thu, May 5, 2016 at 5:33 AM, minisoft_rm <mi...@hotmail.com>
> wrote:
>
>> Dear all,
>>  i searched a number of topics here. but still don't know how to start and
>> use ignite (in client mode) from Tomcat.... you know, I launched the
>> standalone ignite as server node.
>>
>> my code in tomcat web app like this:"
>>
>> this.ignite =
>> Ignition.start(ClientConfigurationFactory.createConfiguration());
>>
>>
>> Class.forName("org.apache.ignite.IgniteJdbcDriver");
>>                         this.conn = DriverManager
>>
>> .getConnection("jdbc:ignite:cfg://cache=b2c_accCache
>> @file:///Users/i306576/Documents/ignite/apache-ignite-fabric-1.5.0.final-bin/examples/config/ignite-jdbc.xml");
>>                         this.cartCacher = new CartCacher();
>>                         this.ic = ignite.cache("b2c_accCache");
>>
>> "
>>
>> the console log show some error mes I don't understand..."
>> Caused by: class org.apache.ignite.IgniteCheckedException: Ignite instance
>> with this name has already been started: b2c_acc
>> "
>>
>> :-(  the thing is.... this kind of client mode is ok without Tomcat...
>>
>> please help~~
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-ignite-users.70518.x6.nabble.com/How-to-start-and-use-ignite-in-Tomcat-tp4776.html
>> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Andrey Gura
> GridGain Systems, Inc.
> www.gridgain.com
>



-- 

Best regards,
Alexei Scherbakov

Re: How to start and use ignite in Tomcat

Posted by Andrey Gura <ag...@gridgain.com>.
Hi,

In order to start clint node you should just execute code like this:

Ignition.setClientMode(true);
Ignition.start();

In this case client node with default configuration will be started. Of
course you can provide own IgniteConfiguration programatically:

IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setClientMode(true);
// ... other settings
Ignition.start(cfg);

or using Spring configuration files:

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans.xsd">

    <bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">

        <property name="clientMode" value="true"/>

        <!-- Explicitly configure TCP discovery SPI to provide list of
initial nodes. -->
        <property name="discoverySpi">
            <bean
class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                <property name="ipFinder">
                    <!--
                        Ignite provides several options for automatic
discovery that can be used
                        instead os static IP based discovery. For
information on all options refer
                        to our documentation:
http://apacheignite.readme.io/docs/cluster-config
                    -->
                    <!-- Uncomment static IP finder to enable static-based
discovery of initial nodes. -->
                    <!--<bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">-->
                    <bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder">
                        <property name="addresses">
                            <list>
                                <!-- In distributed environment, replace
with actual host IP address. -->
                                <value>127.0.0.1:47500..47509</value>
                            </list>
                        </property>
                    </bean>
                </property>
            </bean>
        </property>
    </bean>

</beans>


If you want use JDBC drievr for connection to Ignite cluster there is no
need to create any client nodes.


On Thu, May 5, 2016 at 5:33 AM, minisoft_rm <mi...@hotmail.com> wrote:

> Dear all,
>  i searched a number of topics here. but still don't know how to start and
> use ignite (in client mode) from Tomcat.... you know, I launched the
> standalone ignite as server node.
>
> my code in tomcat web app like this:"
>
> this.ignite =
> Ignition.start(ClientConfigurationFactory.createConfiguration());
>
>
> Class.forName("org.apache.ignite.IgniteJdbcDriver");
>                         this.conn = DriverManager
>
> .getConnection("jdbc:ignite:cfg://cache=b2c_accCache
> @file:///Users/i306576/Documents/ignite/apache-ignite-fabric-1.5.0.final-bin/examples/config/ignite-jdbc.xml");
>                         this.cartCacher = new CartCacher();
>                         this.ic = ignite.cache("b2c_accCache");
>
> "
>
> the console log show some error mes I don't understand..."
> Caused by: class org.apache.ignite.IgniteCheckedException: Ignite instance
> with this name has already been started: b2c_acc
> "
>
> :-(  the thing is.... this kind of client mode is ok without Tomcat...
>
> please help~~
>
>
>
>
> --
> View this message in context:
> http://apache-ignite-users.70518.x6.nabble.com/How-to-start-and-use-ignite-in-Tomcat-tp4776.html
> Sent from the Apache Ignite Users mailing list archive at Nabble.com.
>



-- 
Andrey Gura
GridGain Systems, Inc.
www.gridgain.com