초기커밋
This commit is contained in:
63
GameServer/P2P/P2PDataLogManager.cs
Normal file
63
GameServer/P2P/P2PDataLogManager.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
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<P2PDataLogManager>
|
||||
{
|
||||
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<IDisposable> getAsyncLock() => await m_async_lock.LockAsync();
|
||||
|
||||
public bool logActive() => m_current_log_state.getActive();
|
||||
}
|
||||
Reference in New Issue
Block a user