Uploaded image for project: 'Ignite'
  1. Ignite
  2. IGNITE-6586

Spring bean as ignite service

    XMLWordPrintableJSON

Details

    • Wish
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2
    • None
    • spring
    • None

    Description

      Hello.
      I use a spring-ignite in my application. When using ServiceGrid I noticed a feature.
      I created the following class for the ServiceGrid:

      public class SimpleService implements Service, ApplicationContextAware {
          private ApplicationContext applicationContext;
      
          @Override
          public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
              this.applicationContext = applicationContext;
          }
      
          @Override
          public void init(ServiceContext serviceContext) throws Exception {
              if (applicationContext == null) {
                  System.out.println("ApplicationContext is null");
              }
          }
      
          @Override
          public void execute(ServiceContext serviceContext) throws Exception {
      
          }
      
          @Override
          public void cancel(ServiceContext serviceContext) {
      
          }
      }
      
      <bean id="igniteSpringBean" class="org.apache.ignite.IgniteSpringBean">
              <property name="configuration">
                  <bean class="org.apache.ignite.configuration.IgniteConfiguration">
                      <!-- Enabling the peer-class loading feature. -->
                      <property name="peerClassLoadingEnabled" value="false"/>
                      <property name="gridLogger">
                          <bean class="org.apache.ignite.logger.slf4j.Slf4jLogger"/>
                      </property>
      
                      <property name="userAttributes">
                          <map key-type="java.lang.String" value-type="java.lang.Object">
                              <entry key="simpleservice" value="true" value-type="java.lang.Boolean"/>
                          </map>
                      </property>
      
                      <property name="serviceConfiguration">
                          <list>
                                  <bean class="org.apache.ignite.services.ServiceConfiguration">
                                  <!-- Unique service name -->
                                  <property name="name" value="SimpleService"/>
      
                                  <!-- Service implementation's class -->
                                  <property name="service" >
                                      <bean class="com.myapp.SimpleService"/>
                                  </property>
      
                                  <property name="nodeFilter">
                                      <bean class="com.myapp.ServiceNodeFilter">
                                          <constructor-arg name="serviceName" value="simpleservice"/>
                                      </bean>
                                  </property>
                              </bean>
                          </list>
                      </property>
      
                      <property name="discoverySpi">
                          <bean class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
                              <property name="joinTimeout" value="60000"/>
                              <property name="ipFinder">
                                  <bean class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
                                      <property name="addresses" value="#{'${ignite.addresses.discovery}'.split(',')}"/>
                                  </bean>
                              </property>
                          </bean>
                      </property>
      
                      <!-- see https://issues.apache.org/jira/browse/IGNITE-4377 -->
                      <property name="binaryConfiguration">
                          <bean class="org.apache.ignite.configuration.BinaryConfiguration">
                              <property name="compactFooter" value="false"/>
                          </bean>
                      </property>
                  </bean>
              </property>
      

      After start the application i see following text on the output console:
      ApplicationContext is null

      I see 4 instances on the Memory viewer:

      This is because the ignite serialize spring bean, than deserialize it and used new instance as an instance of the service. Why? Why instance of the service not equals instance in the spring application contex? And is it possible to change this case?

      Thanks.

      Attachments

        Activity

          People

            Unassigned Unassigned
            dekankob Denis Koblov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: