📄 generationmanager.java
字号:
} synchronized public int generateEvent(String theGenMachine, String theGenProcess, int theGenHandle, String theType, String theSubtype, String[] theProperties, Vector mergedClients) { if ((mergedClients == null) || (mergedClients.size() == 0)) return EventService.kNoClientsForEvent; Integer nextID = new Integer(++fEventID); Vector notificationList = new Vector(); EventID eventID = new EventID(nextID.intValue(), theGenHandle, theGenMachine, theGenProcess, theType, theSubtype, theProperties, notificationList); fEventTable.put(nextID, eventID); if ((mergedClients != null) && (mergedClients.size() != 0)) { for (Enumeration e = mergedClients.elements(); e.hasMoreElements();) { Client client = new Client((Client)e.nextElement()); Notification notification = new Notification(client, eventID); notificationList.addElement(notification); fQueue.enqueue(System.currentTimeMillis(), notification); } } else return EventService.kNoClientsForEvent; synchronized(fNotifierThread) { fNotifierThread.notify(); } return nextID.intValue(); } synchronized private int sendMessage(Map propertyMap, Notification notification) { String type = "STAF/Service/Event"; STAFResult fSTAFResult = null; TimeStamp now = new TimeStamp(); Map messageMap = new HashMap(); messageMap.put("eventServiceName", eventServiceName); messageMap.put("eventID", "" + notification.eventID.id); messageMap.put("machine", notification.eventID.generatingMachine); messageMap.put("handleName", notification.eventID.generatingProcess); messageMap.put("handle", "" + notification.eventID.generatingHandle); messageMap.put("timestamp", now.currentDate() + "-" + now.currentTime()); messageMap.put("type", notification.eventID.type); messageMap.put("subtype", notification.eventID.subType); messageMap.put("propertyMap", propertyMap); STAFMarshallingContext mc = new STAFMarshallingContext(); mc.setRootObject(messageMap); String message = mc.marshall(); if (notification.client.fWho.handle != 0) { fSTAFResult = eventSTAFHandle.submit2( notification.client.getMachineName(), "QUEUE", "QUEUE HANDLE " + notification.client.fWho.handle + " PRIORITY " + notification.client.fHow.priority + " TYPE " + type + " MESSAGE :" + message.length() + ":" + message); if (fSTAFResult.rc != fSTAFResult.Ok) { if (fSTAFResult.rc == STAFResult.HandleDoesNotExist || fSTAFResult.rc == STAFResult.NoPathToMachine || fSTAFResult.rc == STAFResult.CommunicationError) { // Unregister the client (which was registered by handle) // since the handle/machine is no longer available String[] subTypes = new String[1]; subTypes[0] = notification.eventID.subType; int rc = eventRegManager.unRegisterClient( notification.client.getMachineName(), notification.client.fWho.handleName, notification.client.fWho.handle, notification.eventID.type, subTypes); } } } else { fSTAFResult = eventSTAFHandle.submit2( notification.client.getMachineName(), "QUEUE", "QUEUE NAME " + notification.client.fWho.handleName + " PRIORITY " + notification.client.fHow.priority + " TYPE " + type + " MESSAGE :" + message.length() + ":" + message); } return fSTAFResult.rc; } synchronized public int ackEvent(int id, String machine, String handleName, int handle) { EventID eventID = (EventID)fEventTable.get(new Integer(id)); if (eventID == null) return EventService.kNoSuchID; Vector clientList = eventID.notificationList; if (clientList != null) { for (Enumeration e = clientList.elements(); e.hasMoreElements();) { Notification notification = (Notification)e.nextElement(); if (((notification.client.fWho.handle == 0) && (notification.client.fWho.handleName). toLowerCase().equals(handleName.toLowerCase())) || ((notification.client.fWho.handle != 0) && (notification.client.fWho.handle == handle)) && notification.client.fWho.machineName.equals(machine)) { notification.client.fHow.maxAttempts = 0; clientList.removeElement(notification); return STAFResult.Ok; //kAckPending; } } return EventService.kNoAckPending; } return EventService.kNoSuchID; } synchronized public Vector getClientsForEvent(int id) { Vector result = null; EventID eventID = (EventID)fEventTable.get(new Integer(id)); if (eventID != null) result = eventID.notificationList; return (result != null ? (Vector)result.clone() : new Vector()); } synchronized public Vector getNotifications() { Vector result = new Vector(); PriorityQueue.PriorityQueueEntry[] entries = fQueue.getQueueCopy(); for (int i = 0; i < fQueue.count(); i++) result.addElement(entries[i]); return result; } void notificationThread() { while (true) { try { if (fQueue.front() == null) { synchronized (fNotifierThread) { fNotifierThread.wait(); } } else { long waitTime = fQueue.topPriority() - System.currentTimeMillis(); if (waitTime > 0) { synchronized (fNotifierThread) { fNotifierThread.wait(waitTime); } } if (System.currentTimeMillis() >= fQueue.topPriority()) notify((Notification)fQueue.dequeue()); } } catch(InterruptedException e) { if (EventService.DEBUG) e.printStackTrace(); } catch(Exception e) { if (EventService.DEBUG) e.printStackTrace(); } } } synchronized private int notify(Notification notification) { Client client = notification.client; EventID eventID = notification.eventID; int id = eventID.id; int fReturnCode = STAFResult.Ok; Map propertyMap = eventID.getPropertyMap(); if (fEventTable.get(new Integer(id)) == null) return EventService.kNoSuchID; if ((client.getMaxAttempts() <= 0)) { Vector clientList = ((EventID)fEventTable.get(new Integer(id))).notificationList; clientList.removeElement(notification); if (clientList.isEmpty()) fEventTable.remove(new Integer(id)); } else { fReturnCode = sendMessage(propertyMap, notification); if ((client.fHow.priority > 0) && (client.fHow.priority >= client.fHow.priorityDelta)) { --client.fHow.priority; } else client.fHow.priority = 0; --client.fHow.maxAttempts; fQueue.enqueue(client.getTimeout() + System.currentTimeMillis(), notification); } return fReturnCode; } public void handleReset() { fEventTable.clear(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -