/** * This constructor is for the ServerPortal that uses worker cache. ServerPortal can be either a * listener(listens on a well known port and redirects the request for a new session to * ServerPortal worker) or a worker. * * @param eqh - EventQueueHAndler on which the events (onSessionNew, onSessionEvent etc) of this * portal will arrive * @param uri - on which the ServerPortal will listen. Can contain a well known port * @param callbacks - implementation of Interface ServerPortal.Callbacks * @param workerProvider - implementation of Interface WorkerCache.WorkerProvider */ public ServerPortal( EventQueueHandler eqh, URI uri, Callbacks callbacks, WorkerCache.WorkerProvider workerProvider) { if (LOG.isDebugEnabled()) { LOG.debug("SP CTOR entry"); } this.eqh = eqh; this.callbacks = callbacks; if (!uri.getScheme().equals("rdma") && !uri.getScheme().equals("tcp")) { LOG.fatal("mal formatted URI: " + uri); } long[] ar = Bridge.startServerPortal(uri.toString(), eqh.getId()); this.setId(ar[0]); this.port = (int) ar[1]; this.name = "jxio.SP[" + Long.toHexString(getId()) + "]"; this.nameForLog = this.name + ": "; if (getId() == 0) { LOG.fatal(this.toLogString() + "there was an error creating ServerPortal"); } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "listening to " + uri); } this.uriPort0 = replacePortInURI(uri, 0); this.uri = replacePortInURI(uri, this.port); this.eqh.addEventable(this); if (workerProvider != null) { this.cache = new WorkerCache(workerProvider); } if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "SP CTOR done"); } }
boolean onEvent(Event ev) { switch (ev.getEventType()) { case 0: // session error event if (ev instanceof EventSession) { int errorType = ((EventSession) ev).getErrorType(); int reason = ((EventSession) ev).getReason(); if (LOG.isDebugEnabled()) { LOG.debug( this.toLogString() + "Received Session Event: Type=" + errorType + ", Reason=" + reason); } EventNameImpl eventName = EventNameImpl.getEventByIndex(errorType); if (eventName == EventNameImpl.PORTAL_CLOSED) { this.eqh.removeEventable(this); if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "portal was closed"); } } EventName eventNameForApp = EventName.getEventByIndex(eventName.getPublishedIndex()); EventReason eventReason = EventReason.getEventByXioIndex(reason); try { callbacks.onSessionEvent(eventNameForApp, eventReason); } catch (Exception e) { eqh.setCaughtException(e); LOG.debug( this.toLogString() + "[onSessionEvent] Callback exception occurred. Event was " + eventName.toString()); } return true; } break; case 6: // on new session if (LOG.isDebugEnabled()) { LOG.debug(this.toLogString() + "Received New Session Event"); } if (ev instanceof EventNewSession) { long ptrSes = ((EventNewSession) ev).getPtrSes(); if (ptrSes == 0) { throw new RuntimeException("malloc of class in C failed"); } String uri = ((EventNewSession) ev).getUri(); String srcIP = ((EventNewSession) ev).getSrcIP(); Worker workerHint = null; String[] arr = uri.split(WorkerCache.CACHE_TAG + "="); if (arr.length > 1 && cache != null) { String key = srcIP + "|" + arr[1]; workerHint = cache.getCachedWorker(key); } String uriStr = arr[0].substring(0, arr[0].length() - 1); ServerSession.SessionKey sesKey = new ServerSession.SessionKey(ptrSes, uriStr); try { this.callbacks.onSessionNew(sesKey, srcIP, workerHint); } catch (Exception e) { eqh.setCaughtException(e); LOG.debug( this.toLogString() + "[onSessionNew] Callback exception occurred. Session Key was " + sesKey.toString() + " and source IP was " + srcIP); } return true; } break; default: break; } LOG.error(this.toLogString() + "Received an un-handled event " + ev.getEventType()); return false; }
public void releaseResources() { mp.deleteMsgPool(); eqh.close(); }
public void run() { // block for a single JXIO incoming event eqh.runEventLoop(1, -1); }