001 package com.croftsoft.apps.chat.user.seri; 002 003 import java.io.*; 004 import java.util.*; 005 006 import com.croftsoft.core.animation.model.ModelId; 007 import com.croftsoft.core.lang.NullArgumentException; 008 import com.croftsoft.core.util.queue.ListQueue; 009 import com.croftsoft.core.util.queue.Queue; 010 011 import com.croftsoft.apps.chat.user.User; 012 import com.croftsoft.apps.chat.user.UserId; 013 014 /********************************************************************* 015 * Serializable User implementation. 016 * 017 * @version 018 * 2003-06-18 019 * @since 020 * 2003-06-05 021 * @author 022 * <a href="https://www.croftsoft.com/">David Wallace Croft</a> 023 *********************************************************************/ 024 025 public final class SeriUser 026 implements Serializable, User 027 ////////////////////////////////////////////////////////////////////// 028 ////////////////////////////////////////////////////////////////////// 029 { 030 031 private static final long serialVersionUID = 0L; 032 033 // 034 035 private static final int MAX_QUEUE_SIZE = 10; 036 037 // 038 039 private final UserId userId; 040 041 private final String username; 042 043 private final Queue messageQueue; 044 045 private final Queue requestQueue; 046 047 // 048 049 private long eventIndex; 050 051 private long lastRequestTime; 052 053 private ModelId modelId; 054 055 private String password; 056 057 ////////////////////////////////////////////////////////////////////// 058 ////////////////////////////////////////////////////////////////////// 059 060 public SeriUser ( 061 UserId userId, 062 String username, 063 String password ) 064 ////////////////////////////////////////////////////////////////////// 065 { 066 NullArgumentException.check ( this.userId = userId ); 067 068 NullArgumentException.check ( this.username = username ); 069 070 setPassword ( password ); 071 072 messageQueue = new ListQueue ( new LinkedList ( ), MAX_QUEUE_SIZE ); 073 074 requestQueue = new ListQueue ( new LinkedList ( ), MAX_QUEUE_SIZE ); 075 076 eventIndex = new Random ( ).nextLong ( ); 077 078 updateLastRequestTime ( ); 079 } 080 081 ////////////////////////////////////////////////////////////////////// 082 ////////////////////////////////////////////////////////////////////// 083 084 public synchronized long getEventIndex ( ) { return eventIndex; } 085 086 public synchronized long getLastRequestTime ( ) 087 ////////////////////////////////////////////////////////////////////// 088 { 089 return lastRequestTime; 090 } 091 092 // 093 094 public Queue getMessageQueue ( ) { return messageQueue; } 095 096 public Queue getRequestQueue ( ) { return requestQueue; } 097 098 public ModelId getModelId ( ) { return modelId; } 099 100 public String getPassword ( ) { return password; } 101 102 public UserId getUserId ( ) { return userId; } 103 104 public String getUsername ( ) { return username; } 105 106 ////////////////////////////////////////////////////////////////////// 107 ////////////////////////////////////////////////////////////////////// 108 109 public synchronized long nextEventIndex ( ) 110 ////////////////////////////////////////////////////////////////////// 111 { 112 return ++eventIndex; 113 } 114 115 public void setModelId ( ModelId modelId ) 116 ////////////////////////////////////////////////////////////////////// 117 { 118 this.modelId = modelId; 119 } 120 121 public void setPassword ( String password ) 122 ////////////////////////////////////////////////////////////////////// 123 { 124 NullArgumentException.check ( this.password = password ); 125 } 126 127 public void updateLastRequestTime ( ) 128 ////////////////////////////////////////////////////////////////////// 129 { 130 lastRequestTime = System.currentTimeMillis ( ); 131 } 132 133 ////////////////////////////////////////////////////////////////////// 134 ////////////////////////////////////////////////////////////////////// 135 }