Class ClientAdapterCustomizer
- java.lang.Object
-
- fish.payara.ejb.http.client.adapter.ClientAdapterCustomizer
-
- All Implemented Interfaces:
ClientAdapter
public final class ClientAdapterCustomizer extends Object implements ClientAdapter
Customizer for externalizing JNDI name matching and name transformation. The class creates a decorator that takes care of matching looked up JNDI names and transforming the jndi name before passed to downstream adapter.Most common use case is represented by method
matchPrefix(String)
: Given the prefix, the downstream adapter is only called when requested name matches prefix, and it is invoked with the prefix stripped from name.Class is intended to use as static import during construction of
CompositeClientAdapter
.import static fish.payara.ejb.http.client.adapter.ClientAdapterCustomizer.*; ... CompositeClientAdapter.builder() .register(customize(JmsStubAdapter.class).matchPrefix("java:comp/jms"), customize(new ConnectionFactoryStub()).matchName(Pattern.compile("jms/.+Factory")::matches)) .build()
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static ClientAdapterCustomizer
customize(ClientAdapter adapterInstance)
Create customizer decorating given instance.static ClientAdapterCustomizer
customize(Class<? extends ClientAdapter> adapterClass)
Create customizer of given class.static ClientAdapterCustomizer
customize(Supplier<ClientAdapter> adapterSupplier)
Create customizer decorating given supplier.Optional<Object>
makeLocalProxy(String jndiName, Context remoteContext)
Call downstream adapter when name matches, with jndiName parameter transformed.ClientAdapterCustomizer
matchName(Predicate<String> name)
Return new customizer with specified predicate for matching a name.ClientAdapterCustomizer
matchPrefix(String prefix)
Return new customizer that matches given prefix, and strips the prefix from the name before invoking downstream adapter.ClientAdapterCustomizer
transformName(Function<String,String> nameTransformation)
Return new customizer with specified name transformation function.
-
-
-
Method Detail
-
makeLocalProxy
public Optional<Object> makeLocalProxy(String jndiName, Context remoteContext) throws NamingException
Call downstream adapter when name matches, with jndiName parameter transformed.- Specified by:
makeLocalProxy
in interfaceClientAdapter
- Parameters:
jndiName
- jndi name requested for lookupremoteContext
- naming context for remote EJB invocation- Returns:
- looked up adapter if downstream adapter returns one
- Throws:
NamingException
- when downstream adapter throws one
-
matchName
public ClientAdapterCustomizer matchName(Predicate<String> name)
Return new customizer with specified predicate for matching a name. The predicates is replaced rather than composed, any current predicate is replaced with the new one in returned instance.- Parameters:
name
- predicate for matching name- Returns:
- new customizer instance
-
transformName
public ClientAdapterCustomizer transformName(Function<String,String> nameTransformation)
Return new customizer with specified name transformation function. The function is replaced rather than composed, any current transformation is replaced with new one in returned instance. Transformation is applied after predicate specified withmatchName(Predicate)
passes- Parameters:
nameTransformation
- JNDI name transformation- Returns:
- new customizer instance
-
matchPrefix
public ClientAdapterCustomizer matchPrefix(String prefix)
Return new customizer that matches given prefix, and strips the prefix from the name before invoking downstream adapter.- Parameters:
prefix
- JNDI name prefix to match and strip- Returns:
- new customizer instance
-
customize
public static ClientAdapterCustomizer customize(Class<? extends ClientAdapter> adapterClass)
Create customizer of given class. Class is instatiated via default constructor immediately.- Parameters:
adapterClass
-- Returns:
- customizer instance
-
customize
public static ClientAdapterCustomizer customize(ClientAdapter adapterInstance)
Create customizer decorating given instance.- Parameters:
adapterInstance
-- Returns:
- customizer instance
-
customize
public static ClientAdapterCustomizer customize(Supplier<ClientAdapter> adapterSupplier)
Create customizer decorating given supplier. Supplier will be invoked at every lookup, but only when JNDI name predicate matches.- Parameters:
adapterSupplier
-- Returns:
- customizer instance
-
-