using System;
using System.Collections.Generic;
using System.Text;
using IndianHealthService.BMXNet.Services;
namespace IndianHealthService.BMXNet
{
///
///
/// Each BMX connection to RPMS contains a single RemoteSessionPool with at least
/// one Session, the primary session. Applications that need additional server processes
/// beyond what can be done with async commands can used the RemoteSessionPool.
///
///
/// Access to the RemoteSessionPool is accomplished by implementing the RemoteSessionPoolConsumer
/// interface on your component/control. Secondary sessions can be opened and closed as they
/// are needed. If the AvailableSessionCount is zero then a null RemoteSession is returned so it
/// is recommend to first check the if a pool HasAvailableSessions before an OpenSession() request.
///
///
/// RemoteSessionPool high-performance can be achieved by keeping RPMS server jobs alive even after
/// secondary sessions are closed. The pool will maintain MaxSessions - 1 number of jobs alive on the
/// server. If the application is finished for awhile needing IdleSessionCount idle jobs, then
/// TerminateIdleSessions() will release those resources on the server. New jobs will then be created
/// on demand.
///
///
///
public interface RemoteSessionPool
{
///
/// True if another secondary session can be opened.
///
///
/// For this version of BMX, the EHR does not support secondary RemoteSessions and this
/// method always returns false. If possible, develop your software using the API so when
/// secondary RemoteSessions are supported your application will work.
///
bool HasAvailableSession { get; }
///
/// The number of additional secondary RemoteSessions that can be opened.
///
int AvailableSessionCount { get; }
///
/// The maximum number of RemoteSessions than can be opened
///
int MaxSessions { get; set; }
///
/// Open a RemoteSession and answer it. If an idle Session exists, it will be recycled
/// and answered. Use Close() on the RemoteSession to release this secondary RemoteSession
/// back to the pool.
///
/// A newly created or recycled RemoteSession or null if the number of RemoteSessions has reach the MaxSessions count
RemoteSession OpenSession();
///
/// Open a new RemoteSession and answer it. If an idle Session exists, it will be recycled
/// and answered. Use Close() on the RemoteSession to release this secondary RemoteSession
/// back to the pool. An implementation of Log can be included to trace RPC execution.
///
///
/// Logging is not heavily used in BMXNET40
///
/// A newly created or recycled RemoteSession or null if the number of RemoteSessions has reach the MaxSessions count
RemoteSession OpenSession(Log aLog);
//Idle session management
int IdleSessionCount { get; }
void TerminateIdleSessions();
//Lifecycle
void Close();
}
}