using System.Collections.Concurrent; using NeoSmart.AsyncLock; using ServerCore; using ServerCommon; namespace GameServer; public class P2PDataInfoLog { public long m_total_packet_count { get; set; } = 0; public long m_total_packet_size { get; set; } = 0; public DateTime m_last_recorded_time { get; set; } = DateTimeHelper.Current; } public class P2PDataLogManager : Singleton { public DateTime m_last_check_time { get; set; } = DateTimeHelper.Current; private AsyncLock m_async_lock = new(); //state 바꿀때 사용 private IP2PDataLogState m_current_log_state; public P2PDataLogManager() { m_current_log_state = new P2PDataWriteIdleState(); m_current_log_state.enter(); } public void changeLogWriteState(IP2PDataLogState nextState) { m_current_log_state.exit(); m_current_log_state = nextState; m_current_log_state.enter(); } public async Task activeMonitoring() { if (m_current_log_state.getActive()) return; using (var _ = await getAsyncLock()) { if (m_current_log_state.getActive()) return; changeLogWriteState(new P2PDataWriteState()); } } public async Task inactiveMonitoring() { if (m_current_log_state.getActive() == false) return; using (var releaser = await getAsyncLock()) { if (m_current_log_state.getActive() == false) return; changeLogWriteState(new P2PDataWriteIdleState()); } } public async Task getAsyncLock() => await m_async_lock.LockAsync(); public bool logActive() => m_current_log_state.getActive(); }