Undeploy Service

classic Classic list List threaded Threaded
6 messages Options
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Undeploy Service

asked by daniel münstermann

Hello!

The only way to "undeploy" a service i have seen so far is to call the cancel-method of the specified service, but if I check the list of deployed services afterwards (via ignite.services().serviceDescriptors()) the cancelled service is still contained in the output... So: How do i get it out there? Do I need to wait for gc?

Thank you very much for any answer =)

BTW: really great work, guys!

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss

pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Undeploy Service

commented by yakov zhdanov

Please pay attention to javadocs.

org.apache.ignite.IgniteServices @IgniteAsyncSupported public void cancel(String name) throws IgniteException Cancels service deployment. If a service with specified name was deployed on the grid, then Service.cancel(ServiceContext) method will be called on it. Note that Ignite cannot guarantee that the service exits from Service.execute(ServiceContext) method whenever Service.cancel(ServiceContext) is called. It is up to the user to make sure that the service code properly reacts to cancellations. Supports asynchronous execution (see IgniteAsyncSupport).

Does you service handle cancellation correctly and exits? Can you share your code here?

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Undeploy Service

commented by daniel münstermann

I am using a boolean 'cancelled' which forces the execute-method to stop execution. In the cancel-method I set this boolean to true so the service will not be used any more.... I know that the cancel-method is executed btw.. Do i need to alter the serviceConfig, setting the service-variable to null to prepare it for gc?

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Undeploy Service

commented by dmitriy setrakyan

Can you please provide a simple code snippet for your service class? This way we will be able to provide better feedback. You can use either GitHub gists, or pastebin to provide your code.

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Undeploy Service

commented by daniel münstermann

This is my simplest implementation. I expect the service to stop working by calling the cancel-method (from another class via ignite.services().cancel("ServiceTest"); ) and so the object won't be used any more. The method stops working correctly but the service is still deployed... So, how to undeploy it after it has stopped working? I'm sure to miss something obvious here...

public class ServiceTest extends Service {
    private boolean cancelled;
    private ServiceConfiguration serviceConfig;
    @IgniteInstanceResource private Ignite ignite;

    public ServiceTest() {
            serviceConfig = new ServiceConfiguration();
            serviceConfig.setName("ServiceTest");
            serviceConfig.setMaxPerNodeCount(maxInstNode);
            serviceConfig.setTotalCount(maxInstCluster);
            serviceConfig.setService(this);
            ignite.services().deploy(serviceConfig);
    }

    @Override
    public void cancel(ServiceContext ctx) {
            cancelled = true;
     }
   
    @Override
    public void init(ServiceContext ctx) throws Exception {
    cancelled = false;
    }

    @Override
    public void execute(ServiceContext ctx) {
    while (!cancelled) {
        System.out.println("test");
    }
    try {
        Thread.sleep(20);
    catch (InterruptedException e{
       //do nothing
    }
   
[...] }


-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss
pgarg pgarg
Reply | Threaded
Open this post in threaded view
|

Re: Undeploy Service

commented by daniel münstermann

OK. Forget my stupid question i have finally found my mistake in logic. I just need to replace the boolean cancelled in the while-loop with while(!ctx.isCancelled())... :rolleyes: Sometimes one just miss the wood for trees...^^

-----
This post is migrated from now discontinued Apache Ignite forum at
http://apacheignite.readme.io/v1.0/discuss