You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by ashishb888 <ab...@gmail.com> on 2020/10/12 10:42:28 UTC
Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
static class ICCall implements IgniteCallable<Long> {
private static final long serialVersionUID = 4278959731940740185L;
@IgniteInstanceResource
private Ignite ignite;
@SpringResource(resourceName = "testService")
private TestService ts;
@SpringApplicationContextResource
private ApplicationContext ac;
private int affKey;
private String cacheName;
ICCall(int affKey, String cacheName) {
this.affKey = affKey;
this.cacheName = cacheName;
}
@Override
public Long call() {
log.debug("affKey: " + affKey + ", cacheName: " + cacheName);
log.debug("beans: " + Arrays.toString(ac.getBeanDefinitionNames()));
return ts.call(affKey, cacheName);
}
}
I am not able to get ApplicationContext by using
@SpringApplicationContextResource. So getting null pointer exception. Did I
miss something?
How one can use @SpringResource & @SpringApplicationContextResource in
IgniteCallable?
BR,
Ashish
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Yes Ilya, it worked. Thank you!
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in IgniteCallable
Posted by Ilya Kazakov <ka...@gmail.com>.
Hello, Asish!
Does it work?
------------------------------
Ilya Kazakov
пн, 9 нояб. 2020 г. в 21:26, ashishb888 <ab...@gmail.com>:
> Thank you Ilya!
>
> I did replace Ignite bean with IgniteSpringBean by using Java configuration
> (and not the XML) as below,
>
> @Slf4j
> @Configuration
> public class BeansConfig {
>
> @Bean
> public IgniteSpringBean igniteSpringBean() {
> log.debug("igniteSpringBean service");
>
> IgniteSpringBean igniteSpringBean = new IgniteSpringBean();
> igniteSpringBean.setConfiguration(igniteConfiguration());
>
> return igniteSpringBean;
> }
>
> private IgniteConfiguration igniteConfiguration() {
> log.debug("igniteConfiguration service");
>
> TcpDiscoverySpi spi = new TcpDiscoverySpi();
>
> spi.setLocalPort(42500);
> spi.setLocalPortRange(100);
>
> TcpDiscoveryVmIpFinder ipFinder = new
> TcpDiscoveryVmIpFinder();
>
> // ipFinder.setAddresses(Arrays.asList("
> 172.17.104.233:42500..42700"));
>
> ipFinder.setAddresses(Arrays.asList("localhost:42500..42700"));
>
> spi.setIpFinder(ipFinder);
> IgniteConfiguration igniteConfiguration = new
> IgniteConfiguration();
>
> igniteConfiguration.setFailureDetectionTimeout(90000);
>
> TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
> commSpi.setLocalPort(42100);
>
> commSpi.setMessageQueueLimit(1024);
> commSpi.setSocketWriteTimeout(10000L);
>
> igniteConfiguration.setCommunicationSpi(commSpi);
>
> // All properties should be in YAML
> igniteConfiguration.setDiscoverySpi(spi);
> igniteConfiguration.setIncludeEventTypes();
> igniteConfiguration.setPeerClassLoadingEnabled(true);
> igniteConfiguration.setGridLogger(new Slf4jLogger());
>
> igniteConfiguration.setWorkDirectory("/var/tmp/ignite/work");
>
> return igniteConfiguration;
> }
> }
>
>
> Anyone looking to make use @SpringResource &
> @SpringApplicationContextResource please refer the below code,
>
> Compute client
> <
> https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource-compute-client>
>
>
> Compute server
> <
> https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource>
>
>
> BR,
> Ashish
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Thank you Ilya!
I did replace Ignite bean with IgniteSpringBean by using Java configuration
(and not the XML) as below,
@Slf4j
@Configuration
public class BeansConfig {
@Bean
public IgniteSpringBean igniteSpringBean() {
log.debug("igniteSpringBean service");
IgniteSpringBean igniteSpringBean = new IgniteSpringBean();
igniteSpringBean.setConfiguration(igniteConfiguration());
return igniteSpringBean;
}
private IgniteConfiguration igniteConfiguration() {
log.debug("igniteConfiguration service");
TcpDiscoverySpi spi = new TcpDiscoverySpi();
spi.setLocalPort(42500);
spi.setLocalPortRange(100);
TcpDiscoveryVmIpFinder ipFinder = new TcpDiscoveryVmIpFinder();
// ipFinder.setAddresses(Arrays.asList("172.17.104.233:42500..42700"));
ipFinder.setAddresses(Arrays.asList("localhost:42500..42700"));
spi.setIpFinder(ipFinder);
IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
igniteConfiguration.setFailureDetectionTimeout(90000);
TcpCommunicationSpi commSpi = new TcpCommunicationSpi();
commSpi.setLocalPort(42100);
commSpi.setMessageQueueLimit(1024);
commSpi.setSocketWriteTimeout(10000L);
igniteConfiguration.setCommunicationSpi(commSpi);
// All properties should be in YAML
igniteConfiguration.setDiscoverySpi(spi);
igniteConfiguration.setIncludeEventTypes();
igniteConfiguration.setPeerClassLoadingEnabled(true);
igniteConfiguration.setGridLogger(new Slf4jLogger());
igniteConfiguration.setWorkDirectory("/var/tmp/ignite/work");
return igniteConfiguration;
}
}
Anyone looking to make use @SpringResource &
@SpringApplicationContextResource please refer the below code,
Compute client
<https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource-compute-client>
Compute server
<https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource>
BR,
Ashish
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in IgniteCallable
Posted by Ilya Kazakov <ka...@gmail.com>.
Hello, Asish!
Try to clean your BeanConfig class. Write this class like (in the client
and in the server app):
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;
@Configuration
@ImportResource({"classpath*:applicationContext.xml"})
public class BeansConfig { }
File applicationContext.xml should be placed in the resources folder.
And write the system configuration to this file in xml. For example:
<?xml version="1.0" encoding="UTF-8"?>
<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="igniteSpringBean" class="org.apache.ignite.IgniteSpringBean">
<property name="configuration">
<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="discoverySpi">
<bean
class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<value>127.0.0.1:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
Pay attention! In igniteSpringBean we use IgniteSpringBean class (not
Ignite). This is a prerequisite if you want to use
@SpringApplicationContextResource in IgniteCallable on remote nodes.
Ilya Kazakov
вт, 3 нояб. 2020 г. в 14:25, ashishb888 <ab...@gmail.com>:
> Hi Ilya,
>
> My bad I forgot to push the changes. Now I just pushed the changes so you
> can find the required details.
>
> BR,
> Ashish
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Hi Ilya,
My bad I forgot to push the changes. Now I just pushed the changes so you
can find the required details.
BR,
Ashish
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in IgniteCallable
Posted by Ilya Kazakov <ka...@gmail.com>.
Hello, Ashish! But I can not find poc.ignite.service.ComputeService class
by your link. Maybe you sent the wrong link?
Check, please.
Ilya Kazakov
вт, 3 нояб. 2020 г. в 12:11, ashishb888 <ab...@gmail.com>:
> Awaiting response. If you anything else let me know
>
> BR,
> Ashish
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Awaiting response. If you anything else let me know
BR,
Ashish
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Hello Ilya,
All actions happens in service package e.g.
poc.ignite.service.ComputeService#main()
Starting server: ignite-spring-resource$ java -jar target/*.jar
Starting client: ignite-spring-resource-compute-client$ java -jar
target/*.jar
I have attached the logs
ignite-spring-resource.log
<http://apache-ignite-users.70518.x6.nabble.com/file/t2180/ignite-spring-resource.log>
ignite-spring-resoure-compute-client.log
<http://apache-ignite-users.70518.x6.nabble.com/file/t2180/ignite-spring-resoure-compute-client.log>
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in IgniteCallable
Posted by Ilya Kazakov <ka...@gmail.com>.
Hello, Ashish!
But I see in your example only config and Main classes. Can you show,
please, some actions in your code?
------------------
Ilya Kazakov
вт, 20 окт. 2020 г. в 17:06, ashishb888 <ab...@gmail.com>:
> Thank you Ilya for the response.
>
> I have two application first one is the server and second one is client.
> Here
> <
> https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource>
>
> you can find the sever application code and here
> <
> https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource-compute-client>
>
> you can find the client application code
>
> BR,
> Ashish
>
>
>
> --
> Sent from: http://apache-ignite-users.70518.x6.nabble.com/
>
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Thank you Ilya for the response.
I have two application first one is the server and second one is client.
Here
<https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource>
you can find the sever application code and here
<https://github.com/ashishb888/ignite-2.8-poc/tree/master/ignite-spring-resource-compute-client>
you can find the client application code
BR,
Ashish
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by Ilya Kazakov <ka...@gmail.com>.
Hello!
I am trying to reproduce your issue and in my example everything is ok. It
looks like you create your spring application without igniteSpringBean. Look
at my example, please.
/////////////////////////////////////////////////////////////////////
public class Main {
public static void main(String[] srgs) throws Exception {
BeanFactory appCtx = new
ClassPathXmlApplicationContext("/spring-bean.xml");
Ignite ignite = (Ignite) appCtx.getBean("igniteSpringBean");
ignite.compute().call(C.getList(10));
}
static public class C implements IgniteCallable<Integer> {
private static final long serialVersionUID = 4278959731940740185L;
@IgniteInstanceResource
private Ignite ignite;
@SpringApplicationContextResource
private ApplicationContext context;
@Override
public Integer call() throws Exception {
System.out.println("Ignite: " + ignite);
System.out.println("Context: " +
context.getBeanDefinitionNames());
System.out.println("---------------");
return 1;
}
public static List<C> getList(int size){
return IntStream.range(0, size - 1).mapToObj(i -> new
C()).collect(Collectors.toList());
}
}
}
///////////////////////////////////////////////////////
// spring-bean.xml
<?xml version="1.0" encoding="UTF-8"?>
<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="beanToInject" class="java.lang.Integer">
<constructor-arg value="111" type="int"/>
</bean>
<bean id="igniteSpringBean" class="org.apache.ignite.IgniteSpringBean">
<property name="configuration">
<bean id="ignite.cfg"
class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="peerClassLoadingEnabled" value="true"/>
<property name="discoverySpi">
<bean
class="org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi">
<property name="ipFinder">
<bean
class="org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder">
<property name="addresses">
<list>
<value>127.0.0.1:47500..47509</value>
</list>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</property>
</bean>
</beans>
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/
Re: Using @SpringResource & @SpringApplicationContextResource in
IgniteCallable
Posted by ashishb888 <ab...@gmail.com>.
Please help
--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/