24 package org.lightjason.agentspeak.action.binding;
35 import javax.annotation.Nonnegative;
36 import javax.annotation.Nonnull;
37 import javax.annotation.Nullable;
38 import java.io.IOException;
39 import java.io.ObjectInputStream;
40 import java.io.ObjectOutputStream;
41 import java.lang.invoke.MethodHandle;
42 import java.lang.invoke.MethodHandles;
43 import java.lang.reflect.Method;
44 import java.text.MessageFormat;
45 import java.util.List;
46 import java.util.Locale;
47 import java.util.Objects;
48 import java.util.stream.Collectors;
49 import java.util.stream.Stream;
86 public CMethodAction( @Nonnull
final Method p_method )
throws IllegalAccessException
89 m_arguments = m_method.getParameterCount();
92 ? m_method.getAnnotation(
IAgentActionName.class ).name().toLowerCase( Locale.ROOT )
93 : m_method.getName().toLowerCase( Locale.ROOT )
95 m_methodhandle = MethodHandles.lookup().unreflect( m_method );
104 private void writeObject(
final ObjectOutputStream p_stream )
throws IOException
106 p_stream.defaultWriteObject();
109 p_stream.writeObject( m_method.getDeclaringClass() );
110 p_stream.writeUTF( m_method.getName() );
111 p_stream.writeObject( m_method.getParameterTypes() );
123 @SuppressWarnings(
"unchecked" )
124 private
void readObject( final ObjectInputStream p_stream ) throws IOException, ClassNotFoundException, NoSuchMethodException, IllegalAccessException
126 p_stream.defaultReadObject();
129 m_method = ( (Class<?>) p_stream.readObject() ).getMethod( p_stream.readUTF(), (Class<?>[])p_stream.readObject() );
130 m_methodhandle = MethodHandles.lookup().unreflect( m_method );
150 @Nonnull
final List<ITerm> p_argument, @Nonnull
final List<ITerm> p_return
165 Stream.of( p_context.agent() ),
167 ).collect( Collectors.toList() )
172 catch (
final Throwable l_throwable )
174 LOGGER.warning( MessageFormat.format(
"binding method [{0}] throws error [{1}] in agent: ",
m_name, l_throwable, p_context.agent() ) );
190 if ( ( Objects.isNull( p_result ) ) || (
void.
class.
equals( p_result.getClass() ) ) )
void writeObject(final ObjectOutputStream p_stream)
serialize call
transient MethodHandle m_methodhandle
method handle
default implementation of an action
transient Method m_method
method reference
final int m_arguments
number of arguments
static< N > IFuzzyValue< N > from( @Nonnull final N p_value)
factory
final int minimalArgumentNumber()
minimum number of arguments
static IPath from( @Nonnull final String p_string)
factor method to build path
class to create a path structure
void readObject(final ObjectInputStream p_stream)
deserializable call
CMethodAction( @Nonnull final Method p_method)
ctor
execution context with local data
final IPath name()
returns the name with path of the action
result for an immutable fuzzy value
static final Logger LOGGER
logger
final IPath m_name
name of the action
IFuzzyValue< Boolean > execute(final boolean p_parallel, @Nonnull final IContext p_context, @Nonnull final List< ITerm > p_argument, @Nonnull final List< ITerm > p_return)
defines a plan-body operation
annotation to define an individual action name
< T > T raw()
cast to any raw value type
static final long serialVersionUID
serial id
final boolean equals(final Object p_object)
static< N > CRawTerm< N > from(final N p_value)
factory for a raw term
action for binding a method.
static IFuzzyValue< Boolean > returnvalues( @Nullable final Object p_result, @Nonnull final List< ITerm > p_return)
creates the returns values of the execution
term structure for simple datatypes