Class JVMBridgeListener
Base class managing events from JVM. Implements IJVMBridgeBase. Extend this base class to manage events from the JVM
public class JVMBridgeListener : JVMBridgeBase<JVMBridgeListener>, IDynamicMetaObjectProvider, IJVMBridgeCore, IEquatable<IJVMBridgeBaseInstance>, IDisposable, IJVMBridgeBaseStatic, IJVMBridgeBase, IJVMBridgeBaseInstance, IJVMBridgeDefinition
- Inheritance
-
JVMBridgeListener
- Implements
- Inherited Members
-
JVMBridgeBase<JVMBridgeListener>.SExecute(IJavaType, string, object, object, object, object, object)JVMBridgeBase<JVMBridgeListener>.New(object, object, object, object, object, object, object, object)JVMBridgeBase.IExecuteWithSignatureArray<TArrayType>(string, string, object, object, object, object)JVMBridgeBase.IExecuteWithSignature<TReturn>(string, string, object, object, object, object, object)
- Extension Methods
Examples
The following is the implementation of the Java ActionListener interface managed from the object JCActionListener (see Java help for implementation)
It use CLRActionEventData as typeparam of the generic CLRListenerEventArgs<TDataClass>
public sealed class CLRActionListener : JVMBridgeListener
{
public override string ClassName { get { return "org.mases.jcobridge.specialized.JCActionListener"; } } // the full name of class, in the JVM counterpart, of the Java class implementing the event
public CLRActionListener(EventHandler<CLRListenerEventArgs<CLRActionEventData>> handler) // the handler with the expected type
{
AddEventHandler("actionPerformed", handler); // allocate the event handler associated to the action the Java interface to be managed in C#
}
}
Constructors
JVMBridgeListener()
Initialize a new instance of JVMBridgeListener
public JVMBridgeListener()
JVMBridgeListener(IJVMBridgeBaseInitializer)
Initializer used internally
public JVMBridgeListener(IJVMBridgeBaseInitializer initializer)
Parameters
initializerIJVMBridgeBaseInitializerAn instance of IJVMBridgeBaseInitializer
Remarks
Shall be available in any class inherited from JVMBridgeBase
JVMBridgeListener(params object[])
Initialize a new instance of JVMBridgeListener
public JVMBridgeListener(params object[] args)
Parameters
argsobject[]The arguments of constructor
Properties
AutoInit
Set to false to externally initialize this JVMBridgeListener instance using InitializeListener(IJVMBridgeBase)
public virtual bool AutoInit { get; }
Property Value
BridgeClassName
Java class name to be instantiated
public override string BridgeClassName { get; }
Property Value
BypassPool
protected override sealed bool BypassPool { get; }
Property Value
IsBridgeCloseable
true if the BridgeClassName implements java.lang.AutoCloseable
public override bool IsBridgeCloseable { get; }
Property Value
IsBridgeListener
true if the BridgeClassName follows the listener pattern of JCOBridge: the BridgeClassName extends a JCListener or implements IJCListener
public override sealed bool IsBridgeListener { get; }
Property Value
IsBridgeStatic
true if the BridgeClassName is a static class, i.e. does not have any public constructor
public override bool IsBridgeStatic { get; }
Property Value
ListenerShallManageEventIndex
An handler invoked from the JVMBridgeListener on each received event to notify the user which can decide to abort the execution for the specific event returning false
public Func<int, bool> ListenerShallManageEventIndex { get; set; }
Property Value
Remarks
By default every event continues the execution and reads the data from JVM; this implies an extra cost which can be limited using the handler associated to this property. Returning false the control is immediately returned to the JVM, however the user has received the notification. It can be useful in scenarios where the user is interested in few events and the other are simply discarded to optimize the execution speed.
ListenerShallManageEventIndexWithData
An handler invoked from the JVMBridgeListener on each received event, if ListenerShallManageEvent(int) or ListenerShallManageEventIndex/ListenerShallManageEventName returned true, to notify the user which can decide to abort the execution for the specific event returning false This is an overload of ListenerShallManageEventIndex which adds the information associated to the event
public Func<int, object, bool> ListenerShallManageEventIndexWithData { get; set; }
Property Value
Remarks
Returning false the control is immediately returned to the JVM, however the user has received the notification with the raw prepared data. It can be useful in scenarios where the user is interested in data associated to few events before the registered handler is invoked and the other are simply discarded to optimize the execution speed.
ListenerShallManageEventName
An handler invoked from the JVMBridgeListener on each received event to notify the user which can decide to abort the execution for the specific event returning false
public Func<string, bool> ListenerShallManageEventName { get; set; }
Property Value
Remarks
By default every event continues the execution and reads the data from JVM; this implies an extra cost which can be limited using the handler associated to this property. Returning false the control is immediately returned to the JVM, however the user has received the notification. It can be useful in scenarios where the user is interested in few events and the other are simply discarded to optimize the execution speed.
ListenerShallManageEventNameWithData
An handler invoked from the JVMBridgeListener on each received event, if ListenerShallManageEvent(int) or ListenerShallManageEventIndex/ListenerShallManageEventName returned true, to notify the user which can decide to abort the execution for the specific event returning false This is an overload of ListenerShallManageEventName which adds the information associated to the event
public Func<string, object, bool> ListenerShallManageEventNameWithData { get; set; }
Property Value
Remarks
Returning false the control is immediately returned to the JVM, however the user has received the notification with the raw prepared data. It can be useful in scenarios where the user is interested in data associated to few events before the registered handler is invoked and the other are simply discarded to optimize the execution speed.
Methods
AddEventHandler(string, EventHandler)
Adds an handler to manage events from JVM
protected int AddEventHandler(string action, EventHandler handler)
Parameters
actionstringThe action to be managed
handlerEventHandlerThe CLR handler associated to the JVM event
Returns
- int
The index asssociated to the event added
AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Adds an handler to manage events from JVM
protected int AddEventHandler<TDataClass>(string action, EventHandler<CLRListenerEventArgs<TDataClass>> handler) where TDataClass : CLREventData
Parameters
actionstringThe action to be managed
handlerEventHandler<CLRListenerEventArgs<TDataClass>>The CLR handler associated to the JVM event
Returns
- int
The index asssociated to the event added
Type Parameters
TDataClassThe class which manages event data in CLR format
ConvertListenerEventIndexToEventName(int)
Returns the event name associated to eventIndex
protected string ConvertListenerEventIndexToEventName(int eventIndex)
Parameters
eventIndexintThe index of the event as returned from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Returns
- string
The event name registered from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Exceptions
- ArgumentException
If
eventIndexis not mapped
ConvertListenerEventNameToEventIndex(string)
Returns the event index associated to eventName
protected int ConvertListenerEventNameToEventIndex(string eventName)
Parameters
eventNamestringThe event name registered from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Returns
- int
The index of the event as returned from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Exceptions
- ArgumentException
If
eventNameis not mapped
Dispose(bool)
Implements the pattern described in https://learn.microsoft.com/en-en/dotnet/standard/garbage-collection/implementing-dispose
protected override void Dispose(bool disposing)
Parameters
disposingboolThe disposing parameter is a bool that indicates whether the method call comes from a Dispose() method (its value is true) or from a finalizer (its value is false)
ListenerShallManageEvent(int)
Invoked from the JVMBridgeListener on each received event to notify the user which can decide to abort the execution for the specific event returning false
protected virtual bool ListenerShallManageEvent(int eventIndex)
Parameters
eventIndexintThe index of the event triggered as returned from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Returns
Remarks
By default every event continues the execution and reads the data from JVM; this implies an extra cost which can be limited using ListenerShallManageEvent(int) or the ListenerShallManageEventIndex/ListenerShallManageEventName handlers. Returning false the control is immediately returned to the JVM, anyway the user has received the notification. It can be useful in scenarios where the user is interested in few events and the other are simply discarded to optimize the execution speed. By default, this function invokes ListenerShallManageEventIndex, then try ListenerShallManageEventName if they are set or return true
ListenerShallManageEvent(int, object)
Invoked from the JVMBridgeListener on each received event, if ListenerShallManageEvent(int) returned true, to notify the user which can decide to abort the execution, for the specific event, returning false.
This is an overload of ListenerShallManageEvent(int) which adds the information associated to the event in data
protected virtual bool ListenerShallManageEvent(int eventIndex, object data)
Parameters
eventIndexintThe index of the event triggered as returned from AddEventHandler(string, EventHandler) or AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
dataobjectThe data associated to
eventIndex: it is null ifeventIndexwas registered with AddEventHandler(string, EventHandler) or it is a prepared instance of CLRListenerEventArgs<TDataClass> if theeventIndexwas registered with AddEventHandler<TDataClass>(string, EventHandler<CLRListenerEventArgs<TDataClass>>)
Returns
Remarks
Returning false the control is immediately returned to the JVM, however the user has received the notification with the raw prepared data. It can be useful in scenarios where the user is interested in data associated to few events before the registered handler is invoked and the other are simply discarded to optimize the execution speed. This function invokes ListenerShallManageEventIndexWithData, then try ListenerShallManageEventNameWithData if they are set or return true by default