/** * Add all the screen listeners. */ public void addListeners() { super.addListeners(); MessageManager messageManager = ((Application)this.getTask().getApplication()).getMessageManager(); if (messageManager != null) { Object source = this; BaseMessageFilter filter = new BaseMessageFilter(MessageConstants.TRX_RETURN_QUEUE, MessageConstants.INTERNET_QUEUE, source, null); filter.addMessageListener(this); messageManager.addMessageFilter(filter); m_intRegistryID = filter.getRegistryID(); } } /**
/** * Free this object. */ public void free() { m_objKey = null; super.free(); } /**
messageFilter.setRegistryID(null); // The needs to be null to add this filter to the receiver. messageFilter.setFilterID(null); // The needs to be null to add this filter to the receiver. remoteFilter.setCreateRemoteFilter(true); // This must be set by the session. remoteFilter.setUpdateRemoteFilter(true); // (This is a transient field you MUST set the initial value) Utility.getLogger().info("EJB addRemoteMessageFilter session: " + remoteSession); remoteFilter = ((BaseMessageReceiver)messageManager.getMessageQueue(remoteFilter.getQueueName(), remoteFilter.getQueueType()).getMessageReceiver()).getMessageFilter(remoteFilter.getFilterID()); // Must look it up remoteFilter.addMessageListener(this); messageFilter.setQueueName(remoteFilter.getQueueName()); // Info to pass to client. messageFilter.setQueueType(remoteFilter.getQueueType()); // Info to pass to client. messageFilter.setFilterID(remoteFilter.getFilterID()); // Info to pass to client. messageFilter.setRegistryID(remoteFilter.getRegistryID()); return messageFilter; // All client needs if the name/type/and ID of the remote filter. (Don't pass the remoteFilter as it's class may not be accessable to thin).
/** * Add this message filter to this receive queue. * Also adds a message filter to the remote queue. * @param The message filter to add. * @return The message filter passed in. */ public void addMessageFilter(MessageFilter messageFilter) { super.addMessageFilter(messageFilter); try { // If at all possible, pass the queue's current session, so the filter is in the proper environment if (((BaseMessageFilter)messageFilter).isCreateRemoteFilter()) // Almost always true { // Create the remote version of this filter. RemoteSession remoteSession = (RemoteSession)((BaseMessageFilter)messageFilter).getRemoteSession(); BaseMessageFilter remoteFilter = m_receiveQueue.addRemoteMessageFilter((BaseMessageFilter)messageFilter, remoteSession); ((BaseMessageFilter)messageFilter).setRemoteFilterInfo(remoteFilter.getQueueName(), remoteFilter.getQueueType(), remoteFilter.getFilterID(), remoteFilter.getRegistryID()); } } catch (RemoteException ex) { ex.printStackTrace(); } } /**
/** * Do I send this message to the remote server? * Remember to check for the filter match. * @return true If I do (default). */ public boolean isSendRemoteMessage(BaseMessage message) { Iterator<BaseMessageFilter> iterator = this.getMessageFilterList().getFilterList(null); // ALL The filters (not just matches). while (iterator.hasNext()) { BaseMessageFilter filter = iterator.next(); if (!filter.isRemoteFilter()) // Always send down when filter is a remote copy if (filter.isSendRemoteMessage(message) == false) return false; // Don't send this message down } return true; } }
/** * AddAvailabilityMessageListeners Method. */ public void addAvailabilityMessageListeners(Product recProduct, ProductScreenRecord screenRecord) { // Override this to add the listeners and message queues (remember to call super) // Create a private messageReceiver and listen for changes MessageManager messageManager = ((Application)this.getTask().getApplication()).getMessageManager(); Integer intRegistryID = null; if (messageManager != null) { Object source = this; BaseMessageFilter messageFilter = new BaseMessageFilter(MessageConstants.TRX_RETURN_QUEUE, MessageConstants.INTERNET_QUEUE, source, null); messageManager.addMessageFilter(messageFilter); this.addProductAvailabilityMessageFilter(recProduct, messageFilter); recProduct.addListener(new FreeOnFreeHandler(messageFilter)); intRegistryID = messageFilter.getRegistryID(); recProduct.addListener(this.getProductAvailabilityHandler(screenRecord, intRegistryID)); } } /**
try { this.registerProcessForMessage(new BaseMessageFilter(MessageConstants.TRX_SEND_QUEUE, MessageConstants.INTERNET_QUEUE, null, null), null, null); recMessageProcessInfo.close(); while (recMessageProcessInfo.hasNext()) if (MessageType.MESSAGE_IN.equals(strMessageType)) if ((strQueueName != null) && (strQueueName.length() > 0)) this.registerProcessForMessage(new BaseMessageFilter(strQueueName, strQueueType, null, null), strProcessClass, properties);
bThinClient = true; messageFilter = this.setupRemoteFilter(messageFilter); // Change the filter? messageFilter.setThinTarget(bThinClient); // This way the server process knows not to send a thick message here (before converting it to thin). BaseMessageManager messageManager = ((Application)this.getTask().getApplication()).getMessageManager(); MessageReceiver messageReceiver = messageManager.getMessageQueue(messageFilter.getQueueName(), messageFilter.getQueueType()).getMessageReceiver(); BaseMessageFilter messageFilterNew = messageFilter.linkRemoteSession(this); // Link the filter and give filter a chance to change the remote version. if (messageFilterNew != messageFilter) if (messageFilterNew.getMessageReceiver() == null) messageReceiver = messageManager.getMessageQueue(messageFilterNew.getQueueName(), messageFilterNew.getQueueType()).getMessageReceiver(); messageReceiver.addMessageFilter(messageFilterNew); messageFilterNew.addMessageListener(this); return messageFilterNew;
filterForSession.addMessageListener(listenerForSession); synchronized (this.getBaseApplet().getRemoteTask())
Map<String,Object> propertiesForFilter = messageFilter.getProperties(); if (propertiesForFilter != null) if (record != null) messageFilter = new GridRecordMessageFilter(record, null, true); messageFilter.setMessageSource(null); // Since this filter auto sets the source if (record != null) messageFilter = new RecordMessageFilter(record, null); messageFilter.setMessageSource(null); newMessageFilter.init(messageFilter.getQueueName(), messageFilter.getQueueType(), null, null); if (newMessageFilter != null) messageFilter = newMessageFilter;
Integer intFilterID = ((BaseMessageFilter)objReturn).getFilterID(); if (intFilterID != null) // If registry ID is null. strReturn = intFilterID.toString(); Integer intRegistryFilterID = ((BaseMessageFilter)objReturn).getRegistryID(); if (intRegistryFilterID != null) // Always strReturn = intRegistryFilterID.toString();
BaseMessageFilter messageFilter = new BaseMessageFilter("chat", "intranet", null, null); Integer intID = new Integer(strParam); messageFilter.setFilterID(intID); return messageFilter;
/** * Are these filters functionally the same? * @return true if they are. */ public boolean isSameFilter(BaseMessageFilter filter) { if (filter.getClass().equals(this.getClass())) { if (this.get(DB_NAME) != null) if (this.get(DB_NAME).equals(filter.get(DB_NAME))) if (this.get(TABLE_NAME) != null) if (this.get(TABLE_NAME).equals(filter.get(TABLE_NAME))) { return true; } if (filter.isFilterMatch(this)) ; } return false; } }
/** * Constructor. */ public void init(String strQueueName, String strQueueType, Object source, Object objKey) { super.init(strQueueName, strQueueType, source, null); m_objKey = objKey; } /**
/** * Does this message header match this filter? * @param messageHeader The message header to check. * @return true if match, false if no match. */ public boolean isFilterMatch(BaseMessageHeader messageHeader) { boolean bIsMatch = super.isFilterMatch(messageHeader); return bIsMatch; } /**
/** * Remove this filter from the filter list. * @param filter The filter to remove. */ public boolean removeThisMessageFilter(BaseMessageFilter filter) { if (m_filter instanceof BaseMessageFilter) { if (m_filter != filter) // Should be this one. return false; // Error m_filter = null; return true; // Success } else return (((Map)m_filter).remove(filter.getFilterID()) != null); } /**
/** * Try to figure out the remote session that this filter belongs to. * In this case, the remotesession should be the RecordOwner. * @return The remote session that belongs to this filter. */ public Object getRemoteSession() { Object remoteSession = super.getRemoteSession(); if (remoteSession == null) if (this.getMessageSource() instanceof Record) { Record record = (Record)this.getMessageSource(); BaseTable table = record.getTable().getCurrentTable(); if (DBParams.CLIENT.equals(table.getSourceType())) remoteSession = (RemoteSession)table.getRemoteTableType(org.jbundle.model.Remote.class); // Only pass the remoteSession if remoteSession is the client part of the remote session! } return remoteSession; } /**
/** * Do I send this message to the remote server? * @return true If I do (default). */ public boolean isSendRemoteMessage(BaseMessage message) { if (message instanceof RecordMessage) // Always { RecordMessageHeader recMessageHeader = (RecordMessageHeader)message.getMessageHeader(); int iChangeType = recMessageHeader.getRecordMessageType(); if (m_iDatabaseType == recMessageHeader.getDatabaseType()) if (DBParams.CLIENT.equals(recMessageHeader.getSourceType())) // Don't send only if Client DB is handling these messages. { if (!(this instanceof GridRecordMessageFilter)) if ((iChangeType == DBConstants.AFTER_UPDATE_TYPE) || (iChangeType == DBConstants.AFTER_ADD_TYPE) || (iChangeType == DBConstants.AFTER_DELETE_TYPE)) return false; // The remote version of me handles this message remotely. if (this instanceof GridRecordMessageFilter) if (iChangeType == DBConstants.AFTER_REQUERY_TYPE) return false; // The remote version of me handles this message remotely. } } return super.isSendRemoteMessage(message); } /**
/** * AddAvailabilityMessageListeners Method. */ public void addAvailabilityMessageListeners(Product recProduct, ProductScreenRecord screenRecord) { // Override this to add the listeners and message queues (remember to call super) // Create a private messageReceiver and listen for changes MessageManager messageManager = ((Application)this.getTask().getApplication()).getMessageManager(); Integer intRegistryID = null; if (messageManager != null) { Object source = this; BaseMessageFilter messageFilter = new BaseMessageFilter(MessageConstants.TRX_RETURN_QUEUE, MessageConstants.INTERNET_QUEUE, source, null); messageManager.addMessageFilter(messageFilter); this.addProductAvailabilityMessageFilter(recProduct, messageFilter); recProduct.addListener(new FreeOnFreeHandler(messageFilter)); intRegistryID = messageFilter.getRegistryID(); recProduct.addListener(this.getProductAvailabilityHandler(screenRecord, intRegistryID)); } } /**
/** * Set the field that owns this listener. * @owner The field that this listener is being added to (if null, this listener is being removed). */ public void setOwner(ListenerOwner owner) { if (owner == null) { if (m_messageListener != null) { m_messageListener.free(); m_messageListener = null; } } super.setOwner(owner); if (owner != null) { Record record = this.getOwner().getRecord(); BaseMessageManager messageManager = ((Application)record.getTask().getApplication()).getMessageManager(); if (messageManager != null) { BaseMessageFilter messageFilter = new BaseMessageFilter(MessageConstants.TRX_RETURN_QUEUE, MessageConstants.INTERNET_QUEUE, this, null); messageManager.addMessageFilter(messageFilter); m_messageListener = new WaitForFieldChangeMessageListener(messageFilter, this); record.setupRecordListener(m_messageListener, false, false); // I need to listen for record changes } } } /**