You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@ignite.apache.org by "Pavel Pereslegin (Jira)" <ji...@apache.org> on 2022/06/28 08:53:00 UTC

[jira] [Updated] (IGNITE-15572) Ability to set custom execution context for Ignite service.

|  ![](cid:jira-generated-image-avatar-dc02bb1b-f87c-4e11-a279-bf8226f9c5ed) |
[Pavel
Pereslegin](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=xtern)
**updated** an issue  
---|---  
|  
---  
|  [Ignite](https://issues.apache.org/jira/browse/IGNITE) / [![New
Feature](cid:jira-generated-image-
avatar-30992bfd-6ba2-4f2a-b141-e1cb5e52bf56)](https://issues.apache.org/jira/browse/IGNITE-15572)
[IGNITE-15572](https://issues.apache.org/jira/browse/IGNITE-15572)  
---  
[Ability to set custom execution context for Ignite
service.](https://issues.apache.org/jira/browse/IGNITE-15572)  
| Change By: |  [Pavel
Pereslegin](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=xtern)  
---|---  
|  In traditional microservices, we have the ability to set a custom execution
context. For example, a REST service may obtain the session ID from the
request. We can say that each client request, in this case, has a set of
explicit and implicit parameters. One of the implicit parameters is a session
identifier that can be passed to the service using request headers. It would
be nice to have a similar feature in Ignite services.  
  
The basic idea behind the implementation:  
1\. Allow the user to bind the "execution context" to the service proxy
object.  
2\. Pass this context as an additional implicit parameter each time the user
service method is called.  
h3. API proposal ({color:#FF0000}outdated, actual Java API in
IGNITE-15794{color}) .  
h4. 1. Using a custom annotation (ServiceRequestContextResource) and reading
context attributes with a function.  
{code:java}  
MyService proxy = ignite.services().serviceProxy("svc", ...
Collections.singletonMap("login", "user1"));  
  
public class MyServiceImpl implements MyService {  
    @ServiceRequestContextResource  
    private Function<String, Object> ctxFunc;  
  
    @Override public void serviceMethod() {  
        String login = (String)ctxFunc.apply("login");  
    }  
    ...  
}{code}  
h4. 2. Using a new method of the existing ServiceContext.  
{code:java}  
MyService proxy = ignite.services().serviceProxy("svc", ...
Collections.singletonMap("login", "user1"));  
  
public class MyServiceImpl implements MyService {  
    private ServiceContext svcCtx;  
  
    @Override public void init(ServiceContext svcCtx) {  
        this.svcCtx = svcCtx;  
    }  
  
    @Override public void serviceMethod() {  
        String user = svcCtx.attribute("login");  
        // and/or  
        String user = (String)svcCtx.attributes().get("login");  
    }  
    ...   
}{code}  
h4. The next two options require wrapping Map<String, Object> into a new
ServiceRequestContext class.  
h4. 3. Read context "wrapper" using special annotation and supplier.  
{code:java}  
MyService proxy = ignite.services().serviceProxy("svc", ... new
ServiceRequestContext("login", "user1"), 0);  
  
public class MyServiceImpl implements MyService {  
    @ServiceRequestContextResource  
    Supplier<ServiceRequestContext> ctxSupplier;  
  
    @Override public void serviceMethod() {  
        String login = ctxSupplier.get().attribute("login");  
    }  
    ...  
}  
{code}  
h4. 4. Using the special static method of the "wrapper" class.  
{code:java}  
MyService proxy = ignite.services().serviceProxy("svc", ... new
ServiceRequestContext("login", "user1"), 0);  
  
public class MyServiceImpl implements MyService {  
    @Override public void serviceMethod() {    
        String login = ServiceRequestContext.current().attribute("login");  
    }  
    ...  
}  
{code}  
---  
|  |  [ ![Add Comment](cid:jira-generated-image-static-comment-
icon-697a8234-b337-4162-8ef0-657c742fe588)
](https://issues.apache.org/jira/browse/IGNITE-15572#add-comment "Add
Comment") |  [Add
Comment](https://issues.apache.org/jira/browse/IGNITE-15572#add-comment "Add
Comment")  
---|---  
  
|  This message was sent by Atlassian Jira (v8.20.10#820010-sha1:ace47f9) |  |
![Atlassian logo](https://issues.apache.org/jira/images/mail/atlassian-email-
logo.png)  
---