1 17 package org.alfresco.filesys.smb.server.notify; 18 19 import java.util.Date ; 20 21 import org.alfresco.filesys.server.filesys.DiskDeviceContext; 22 import org.alfresco.filesys.server.filesys.NetworkFile; 23 import org.alfresco.filesys.server.filesys.NotifyChange; 24 import org.alfresco.filesys.smb.server.SMBSrvSession; 25 26 29 public class NotifyRequest 30 { 31 32 34 public final static long DefaultRequestTimeout = 10000L; 36 38 private int m_filter; 39 40 43 private boolean m_watchTree; 44 45 47 private SMBSrvSession m_sess; 48 49 51 private NetworkFile m_watchDir; 52 53 55 private String m_watchPath; 56 57 63 private int m_mid; 64 private int m_tid; 65 private int m_pid; 66 private int m_uid; 67 68 70 private int m_maxQueueLen; 71 72 74 private DiskDeviceContext m_diskCtx; 75 76 78 private NotifyChangeEventList m_bufferedEvents; 79 80 82 private boolean m_completed; 83 private long m_expiresAt; 84 85 89 private boolean m_notifyEnum; 90 91 104 public NotifyRequest(int filter, boolean watchTree, SMBSrvSession sess, NetworkFile dir, int mid, int tid, int pid, 105 int uid, int qlen) 106 { 107 m_filter = filter; 108 m_watchTree = watchTree; 109 m_sess = sess; 110 m_watchDir = dir; 111 112 m_mid = mid; 113 m_tid = tid; 114 m_pid = pid; 115 m_uid = uid; 116 117 m_maxQueueLen = qlen; 118 119 121 m_watchPath = m_watchDir.getFullName().toUpperCase(); 122 if (m_watchPath.length() == 0) 123 m_watchPath = "\\"; 124 else if (m_watchPath.indexOf('/') != -1) 125 m_watchPath.replace('/', '\\'); 126 } 127 128 133 public final int getFilter() 134 { 135 return m_filter; 136 } 137 138 143 public final boolean isCompleted() 144 { 145 return m_completed; 146 } 147 148 154 public final boolean hasExpired(long curTime) 155 { 156 if (isCompleted() == false) 157 return false; 158 else if (m_expiresAt < curTime) 159 return true; 160 return false; 161 } 162 163 169 public final boolean hasFileNameChange() 170 { 171 return hasFilter(NotifyChange.FileName); 172 } 173 174 180 public final boolean hasDirectoryNameChange() 181 { 182 return hasFilter(NotifyChange.DirectoryName); 183 } 184 185 190 public final boolean hasAttributeChange() 191 { 192 return hasFilter(NotifyChange.Attributes); 193 } 194 195 200 public final boolean hasFileSizeChange() 201 { 202 return hasFilter(NotifyChange.Size); 203 } 204 205 210 public final boolean hasFileWriteTimeChange() 211 { 212 return hasFilter(NotifyChange.LastWrite); 213 } 214 215 220 public final boolean hasFileAccessTimeChange() 221 { 222 return hasFilter(NotifyChange.LastAccess); 223 } 224 225 230 public final boolean hasFileCreateTimeChange() 231 { 232 return hasFilter(NotifyChange.Creation); 233 } 234 235 240 public final boolean hasSecurityDescriptorChange() 241 { 242 return hasFilter(NotifyChange.Security); 243 } 244 245 251 public final boolean hasFilter(int flag) 252 { 253 return (m_filter & flag) != 0 ? true : false; 254 } 255 256 261 public final boolean hasNotifyEnum() 262 { 263 return m_notifyEnum; 264 } 265 266 271 public final boolean hasWatchTree() 272 { 273 return m_watchTree; 274 } 275 276 281 public final SMBSrvSession getSession() 282 { 283 return m_sess; 284 } 285 286 291 public final NetworkFile getDirectory() 292 { 293 return m_watchDir; 294 } 295 296 301 public final String getWatchPath() 302 { 303 return m_watchPath; 304 } 305 306 311 public final int getMultiplexId() 312 { 313 return m_mid; 314 } 315 316 321 public final int getTreeId() 322 { 323 return m_tid; 324 } 325 326 331 public final int getProcessId() 332 { 333 return m_pid; 334 } 335 336 341 public final int getUserId() 342 { 343 return m_uid; 344 } 345 346 352 public final long getExpiryTime() 353 { 354 return m_expiresAt; 355 } 356 357 362 public final DiskDeviceContext getDiskContext() 363 { 364 return m_diskCtx; 365 } 366 367 373 public final int getMaximumQueueLength() 374 { 375 return m_maxQueueLen; 376 } 377 378 383 public final boolean hasBufferedEvents() 384 { 385 if (m_bufferedEvents != null && m_bufferedEvents.numberOfEvents() > 0) 386 return true; 387 return false; 388 } 389 390 395 public final NotifyChangeEventList getBufferedEventList() 396 { 397 return m_bufferedEvents; 398 } 399 400 405 public final void addEvent(NotifyChangeEvent evt) 406 { 407 408 410 if (hasNotifyEnum()) 411 return; 412 413 415 if (m_bufferedEvents == null) 416 m_bufferedEvents = new NotifyChangeEventList(); 417 418 420 if (m_bufferedEvents.numberOfEvents() < getMaximumQueueLength()) 421 { 422 423 425 m_bufferedEvents.addEvent(evt); 426 } 427 else 428 { 429 430 433 removeAllEvents(); 434 setNotifyEnum(true); 435 } 436 } 437 438 441 public final void removeAllEvents() 442 { 443 if (m_bufferedEvents != null) 444 { 445 m_bufferedEvents.removeAllEvents(); 446 m_bufferedEvents = null; 447 } 448 } 449 450 453 public final void clearBufferedEvents() 454 { 455 m_bufferedEvents = null; 456 } 457 458 463 public final void setNotifyEnum(boolean ena) 464 { 465 m_notifyEnum = ena; 466 } 467 468 473 protected final void setDiskContext(DiskDeviceContext ctx) 474 { 475 m_diskCtx = ctx; 476 } 477 478 483 public final void setMultiplexId(int mid) 484 { 485 m_mid = mid; 486 } 487 488 493 public final void setCompleted(boolean comp) 494 { 495 m_completed = comp; 496 497 if (comp) 498 m_expiresAt = System.currentTimeMillis() + DefaultRequestTimeout; 499 } 500 501 507 public final void setCompleted(boolean comp, long expires) 508 { 509 m_completed = comp; 510 m_expiresAt = expires; 511 } 512 513 518 public String toString() 519 { 520 StringBuffer str = new StringBuffer (); 521 522 str.append("["); 523 524 str.append(getSession().getUniqueId()); 525 str.append(":"); 526 527 if (getWatchPath().length() == 0) 528 str.append("Root"); 529 else 530 str.append(getWatchPath()); 531 str.append(":"); 532 533 if (hasFileNameChange()) 534 str.append("File,"); 535 536 if (hasDirectoryNameChange()) 537 str.append("Dir,"); 538 539 if (hasAttributeChange()) 540 str.append("Attr,"); 541 542 if (hasFileSizeChange()) 543 str.append("Size,"); 544 545 if (hasFileWriteTimeChange()) 546 str.append("Write,"); 547 548 if (hasFileAccessTimeChange()) 549 str.append("Access,"); 550 551 if (hasFileCreateTimeChange()) 552 str.append("Create,"); 553 554 if (hasSecurityDescriptorChange()) 555 str.append("Security,"); 556 557 if (hasWatchTree()) 558 str.append("Tree"); 559 else 560 str.append("NoTree"); 561 562 str.append(" MID="); 563 str.append(getMultiplexId()); 564 565 str.append(" PID="); 566 str.append(getProcessId()); 567 568 str.append(" TID="); 569 str.append(getTreeId()); 570 571 str.append(" UID="); 572 str.append(getUserId()); 573 574 if (isCompleted()) 575 { 576 str.append(",Completed,TMO="); 577 str.append(new Date (getExpiryTime()).toString()); 578 } 579 580 str.append(",Queue="); 581 str.append(getMaximumQueueLength()); 582 if (hasBufferedEvents()) 583 { 584 str.append("/"); 585 str.append(getBufferedEventList().numberOfEvents()); 586 } 587 588 if (hasNotifyEnum()) 589 str.append(",ENUM"); 590 591 str.append("]"); 592 593 return str.toString(); 594 } 595 } 596 | Popular Tags |