1 17 package org.alfresco.filesys.server; 18 19 import java.net.InetAddress ; 20 import java.util.Vector ; 21 22 import org.alfresco.filesys.server.auth.SrvAuthenticator; 23 import org.alfresco.filesys.server.auth.acl.AccessControlManager; 24 import org.alfresco.filesys.server.config.ServerConfiguration; 25 import org.alfresco.filesys.server.core.ShareMapper; 26 import org.alfresco.filesys.server.core.SharedDevice; 27 import org.alfresco.filesys.server.core.SharedDeviceList; 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 31 36 public abstract class NetworkServer 37 { 38 private static final Log logger = LogFactory.getLog("org.alfresco.filesys"); 39 40 42 private String m_protoName; 43 44 46 private String m_version; 47 48 private ServerConfiguration m_config; 50 51 53 private boolean m_debug; 54 private int m_debugFlags; 55 56 58 private InetAddress [] m_ipAddr; 59 60 62 private boolean m_shutdown = false; 63 private boolean m_active = false; 64 65 67 private Exception m_exception; 68 69 71 private ServerListener m_listener; 72 73 75 private Vector <SessionListener> m_sessListeners; 76 77 83 public NetworkServer(String proto, ServerConfiguration config) 84 { 85 m_protoName = proto; 86 m_config = config; 87 } 88 89 94 public final ServerConfiguration getConfiguration() 95 { 96 return m_config; 97 } 98 99 104 public final SrvAuthenticator getAuthenticator() 105 { 106 return getConfiguration().getAuthenticator(); 107 } 108 109 114 public final boolean hasAccessControlManager() 115 { 116 return getConfiguration().getAccessControlManager() != null ? true : false; 117 } 118 119 124 public final AccessControlManager getAccessControlManager() 125 { 126 return getConfiguration().getAccessControlManager(); 127 } 128 129 134 public final String getServerName() 135 { 136 return m_config.getServerName(); 137 } 138 139 144 public final InetAddress [] getServerAddresses() 145 { 146 return m_ipAddr; 147 } 148 149 154 public final ShareMapper getShareMapper() 155 { 156 return m_config.getShareMapper(); 157 } 158 159 166 public final SharedDeviceList getShareList(String host, SrvSession sess) 167 { 168 return getConfiguration().getShareMapper().getShareList(host, sess, false); 169 } 170 171 178 public final SharedDeviceList getFullShareList(String host, SrvSession sess) 179 { 180 return getConfiguration().getShareMapper().getShareList(host, sess, true); 181 } 182 183 194 public final SharedDevice findShare(String host, String name, int typ, SrvSession sess, boolean create) 195 throws Exception 196 { 197 198 200 SharedDevice dev = getConfiguration().getShareMapper().findShare(host, name, typ, sess, create); 201 202 204 return dev; 205 } 206 207 212 public final boolean isActive() 213 { 214 return m_active; 215 } 216 217 222 223 public final String isVersion() 224 { 225 return m_version; 226 } 227 228 233 public final boolean hasException() 234 { 235 return m_exception != null ? true : false; 236 } 237 238 243 public final Exception getException() 244 { 245 return m_exception; 246 } 247 248 251 public final void clearException() 252 { 253 m_exception = null; 254 } 255 256 261 public final String getProtocolName() 262 { 263 return m_protoName; 264 } 265 266 271 public final boolean hasDebug() 272 { 273 return m_debug; 274 } 275 276 281 public final boolean hasDebugFlag(int flg) 282 { 283 return (m_debugFlags & flg) != 0 ? true : false; 284 } 285 286 291 public final boolean hasShutdown() 292 { 293 return m_shutdown; 294 } 295 296 301 protected void setActive(boolean active) 302 { 303 m_active = active; 304 } 305 306 311 protected final void setException(Exception ex) 312 { 313 m_exception = ex; 314 } 315 316 321 protected final void setServerAddresses(InetAddress [] addrs) 322 { 323 m_ipAddr = addrs; 324 } 325 326 331 protected final void setVersion(String ver) 332 { 333 m_version = ver; 334 } 335 336 341 protected final void setDebug(boolean dbg) 342 { 343 m_debug = dbg; 344 } 345 346 351 protected final void setDebugFlags(int flags) 352 { 353 m_debugFlags = flags; 354 setDebug(flags == 0 ? false : true); 355 } 356 357 362 protected final void setShutdown(boolean ena) 363 { 364 m_shutdown = ena; 365 } 366 367 372 public final void addServerListener(ServerListener l) 373 { 374 m_listener = l; 375 } 376 377 382 public final void removeServerListener(ServerListener l) 383 { 384 if (m_listener == l) 385 m_listener = null; 386 } 387 388 393 public final void addSessionListener(SessionListener l) 394 { 395 396 398 if (m_sessListeners == null) 399 m_sessListeners = new Vector <SessionListener>(); 400 m_sessListeners.add(l); 401 } 402 403 408 public final void removeSessionListener(SessionListener l) 409 { 410 411 413 if (m_sessListeners == null) 414 return; 415 m_sessListeners.removeElement(l); 416 } 417 418 423 protected final void fireServerEvent(int event) 424 { 425 426 428 if (m_listener != null) 429 { 430 try 431 { 432 m_listener.serverStatusEvent(this, event); 433 } 434 catch (Exception ex) 435 { 436 } 437 } 438 } 439 440 443 public abstract void startServer(); 444 445 450 public abstract void shutdownServer(boolean immediate); 451 452 457 protected final void fireSessionClosedEvent(SrvSession sess) 458 { 459 460 462 if (m_sessListeners == null || m_sessListeners.size() == 0) 463 return; 464 465 467 for (int i = 0; i < m_sessListeners.size(); i++) 468 { 469 470 472 try 473 { 474 SessionListener sessListener = (SessionListener) m_sessListeners.elementAt(i); 475 sessListener.sessionClosed(sess); 476 } 477 catch (Exception ex) 478 { 479 logger.error("Session listener error [closed]: ", ex); 480 } 481 } 482 } 483 484 489 protected final void fireSessionLoggedOnEvent(SrvSession sess) 490 { 491 492 494 if (m_sessListeners == null || m_sessListeners.size() == 0) 495 return; 496 497 499 for (int i = 0; i < m_sessListeners.size(); i++) 500 { 501 502 504 try 505 { 506 SessionListener sessListener = (SessionListener) m_sessListeners.elementAt(i); 507 sessListener.sessionLoggedOn(sess); 508 } 509 catch (Exception ex) 510 { 511 logger.error("Session listener error [logon]: ", ex); 512 } 513 } 514 } 515 516 521 protected final void fireSessionOpenEvent(SrvSession sess) 522 { 523 524 526 if (m_sessListeners == null || m_sessListeners.size() == 0) 527 return; 528 529 531 for (int i = 0; i < m_sessListeners.size(); i++) 532 { 533 534 536 try 537 { 538 SessionListener sessListener = (SessionListener) m_sessListeners.elementAt(i); 539 sessListener.sessionCreated(sess); 540 } 541 catch (Exception ex) 542 { 543 logger.error("Session listener error [open]: ", ex); 544 } 545 } 546 } 547 } 548 | Popular Tags |