Files
spark/src/DataStreamSuite/PubSub/Server/Communication/IPubsubMessageHubBase.cs
T
2024-01-13 23:45:51 -05:00

68 lines
2.6 KiB
C#

using System;
using System.Collections;
using BCG.Utilities.General;
using System.IO;
using System.Collections.Generic;
using mbts;
namespace BCG {
public delegate void PubSubServerConnectionStatusChange(string peerURL, bool connection);
public delegate void PubSubServerDataDelegate(string sender, byte[] data);
/// <summary>
/// Encapsulates PubsubServer's communication with the
/// rest of the world. Has send and get methods, and also
/// an event to tell if a client connects or disconnects.
/// this event is prompted by the doWork.
/// </summary>
public interface IPubsubMessageHub : IWorker {
/// <summary>
/// The port that the message hub is listening on. Return -1 if you're not listening on a port, i.e. for hte case of multicast
/// </summary>
int port { get; }
/// <summary>
/// register or unregister callback for data. The callback when data
/// is available will be called in an arbitrary thread. Its an orthogonal
/// way to receive data, and can only be used exclusively with the
/// getUpdates. The delegate will be fired on an arbitrary thread.
/// </summary>
/// <param name="?"></param>
void registerDataCallback(PubSubServerDataDelegate del);
/// <summary>
/// registers a connection callback. this callback
/// will be fired within the doWork call.
/// </summary>
/// <param name="del"></param>
/// <param name="register"></param>
void registerConnectionCallback(PubSubServerConnectionStatusChange del);
/// <summary>
/// this is where this interface starts communication with the
/// rest of the world. Obvioulsy, the resgiters should be
/// called before the start, or else the user might miss
/// connections and data.
/// </summary>
void activate();
/// <summary>
/// Gets the updates and the source of the data
/// from the clients. Returns either if timeout
/// expires or maxElements have been fetched.
/// </summary>
/// <param name="sender"></param>
/// <param name="data"></param>
List<Pair<string, byte[]>> getUpdates(TimeSpan timeout, int maxElements);
/// <summary>
/// sends data to the receiver.
/// </summary>
/// <param name="receiver"></param>
/// <param name="data"></param>
bool send(string receiver, byte[] data);
/// <summary>
/// sends the data stored in the current position in the Stream.
/// </summary>
/// <param name="receiver"></param>
/// <param name="str"></param>
/// <returns></returns>
bool send(string receiver, Stream str);
}
}