1 package org.asteriskjava.live.internal;
2
3 import java.util.Date;
4
5 import org.asteriskjava.live.AsteriskQueueEntry;
6 import org.asteriskjava.live.QueueEntryState;
7
8
9
10
11
12
13 class AsteriskQueueEntryImpl extends AbstractLiveObject implements AsteriskQueueEntry
14 {
15 private final AsteriskQueueImpl queue;
16 private final AsteriskChannelImpl channel;
17 private final Date dateJoined;
18
19 private Date dateLeft;
20 private QueueEntryState state;
21
22
23
24 private int reportedPosition;
25
26
27
28 private int position = POSITION_UNDETERMINED;
29
30 AsteriskQueueEntryImpl(AsteriskServerImpl server, AsteriskQueueImpl queue,
31 AsteriskChannelImpl channel, int reportedPosition, Date dateJoined)
32 {
33 super(server);
34 this.queue = queue;
35 this.channel = channel;
36 this.dateJoined = dateJoined;
37 this.state = QueueEntryState.JOINED;
38 this.reportedPosition = reportedPosition;
39 }
40
41 public String getChannelName()
42 {
43 return channel.getName();
44 }
45
46 public AsteriskQueueImpl getQueue()
47 {
48 return queue;
49 }
50
51 public AsteriskChannelImpl getChannel()
52 {
53 return channel;
54 }
55
56 public Date getDateJoined()
57 {
58 return dateJoined;
59 }
60
61 public Date getDateLeft()
62 {
63 return dateLeft;
64 }
65
66
67
68
69
70
71 void left(Date dateLeft)
72 {
73 QueueEntryState oldState;
74 synchronized (this)
75 {
76 oldState = this.state;
77 this.dateLeft = dateLeft;
78 this.state = QueueEntryState.LEFT;
79 }
80 firePropertyChange(PROPERTY_STATE, oldState, state);
81 }
82
83 public QueueEntryState getState()
84 {
85 return state;
86 }
87
88
89
90
91
92
93
94
95 public int getReportedPosition()
96 {
97 return reportedPosition;
98 }
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114 public int getPosition()
115 {
116 return position;
117 }
118
119 void setPosition(int position)
120 {
121 int oldPosition = this.position;
122 this.position = position;
123 firePropertyChange(PROPERTY_POSITION, oldPosition, position);
124 }
125
126 void setReportedPosition(int reportedPosition)
127 {
128 int oldPosition = this.reportedPosition;
129 this.reportedPosition = reportedPosition;
130 firePropertyChange(PROPERTY_REPORTED_POSITION, oldPosition, reportedPosition);
131 }
132
133 @Override
134 public String toString()
135 {
136 StringBuffer sb;
137 int systemHashcode;
138
139 sb = new StringBuffer("AsteriskQueueEntry[");
140
141 synchronized (this)
142 {
143 sb.append("dateJoined=").append(getDateJoined()).append(",");
144 sb.append("postition=").append(getPosition()).append(",");
145 sb.append("dateLeft=").append(getDateLeft()).append(",");
146 systemHashcode = System.identityHashCode(this);
147 }
148 if (channel != null)
149 {
150 sb.append("channel=AsteriskChannel[");
151 synchronized (channel)
152 {
153 sb.append("id='").append(channel.getId()).append("',");
154 sb.append("name='").append(channel.getName()).append("'],");
155 }
156 }
157 else
158 {
159 sb.append("channel=null,");
160 }
161 sb.append("systemHashcode=").append(systemHashcode);
162 sb.append("]");
163
164 return sb.toString();
165 }
166 }