私は、以下のコードと同様の機能を持つ Java コードを作成する任務を負っています。現在、コードが何をしているのか、Java で効果をシミュレートする方法を正確に理解するのに苦労しています。
#region "Send Aggregate Event"
/// <summary>
/// Delegate for async sending the AggregateEvent
/// </summary>
/// <param name="request"></param>
public delegate void SendAggregateEventAsync(AE request);
SendAggregateEventAsync _sendAggregateEventAsync;
/// <summary>
/// IAsyncResult pattern to async send the AggregateEvent
/// </summary>
/// <param name="request"></param>
/// <param name="callback"></param>
/// <param name="state"></param>
/// <returns></returns>
public IAsyncResult BeginSendAggregateEvent(AE request, AsyncCallback callback, Object state)
{
_sendAggregateEventAsync = new SendAggregateEventAsync(SendAggregateEvent);
return _sendAggregateEventAsync.BeginInvoke(request, callback, state);
}
public void EndSendAggregateEvent(IAsyncResult result)
{
object state = result.AsyncState;
_sendAggregateEventAsync.EndInvoke(result);
}
/// <summary>
/// Send an aggregate event to the Device Webserver
/// </summary>
/// <param name="request">The AggregateEvent request</param>
public void SendAggregateEvent(AE request)
{
if (request == null) throw new ArgumentNullException("request");
String message = ChangeDatesToUTC(MessageHelper.SerializeObject( typeof(AE), request), new String[] { "EventTime" }, url);
SendMessage(message);
}
#endregion
他にもいくつかのイベントがあり、すべて上記のコードと似ています。コメントから、コードが SendAggregateEvent メソッドを非同期的に処理することを意図していることがわかります。私が理解していないのは、デリゲート修飾子が使用される理由、またはこのタイプの非同期処理を Java で複製する方法です。
また、このスレを読んでから
Java でデリゲート機能をシミュレートする「簡単な」方法がないことを理解しています。SendAggregateEvent メソッドを非同期で処理するには、デリゲート機能が必要ですか? そうでない場合、誰かが私がこれを行う方法を提案できますか?