//if (sessionName != null) getQos.getData().getClientProperties().remove("__sessionName");
String prefix = getQos.getData().getClientProperty("__prefix", (String)null);
//if (prefix != null) publishQos.getData().getClientProperties().remove("__prefix");
if (log.isLoggable(Level.FINE)) log.fine("Get " + xmlKey.getOid() + " prefix=" + prefix + " on session=" + otherSessionInfo.getSessionName().getRelativeName());
ClientProperty[] props = otherSessionInfo.getRemotePropertyArr();
GetReturnQosServer retQos = new GetReturnQosServer(glob, null, null);
for (int i=0; i<props.length; i++)
retQos.getData().getClientProperties().put(props[i].getName(), props[i]);
MsgUnit[] msgUnitArr = new MsgUnit[1];
GetKey gk = new GetKey(glob, xmlKey.getOid());
msgUnitArr[0] = new MsgUnit(gk.getData(), new byte[0], retQos.getData());
return msgUnitArr;
}
if (xmlKey.isAdministrative()) {
if (!glob.supportAdministrative())
throw new XmlBlasterException(glob, ErrorCode.RESOURCE_ADMIN_UNAVAILABLE, ME, "Sorry administrative get() is not available, try to configure xmlBlaster.");
MsgUnit[] raw = glob.getMomClientGateway().getCommand(sessionInfo, xmlKey, getQos.getData());
if (getQos.getWantContent()) return raw;
MsgUnit[] msgUnitArr = new MsgUnit[raw.length];
for(int i=0; i<raw.length; i++) {
// byte[] cont = (getQos.getWantContent()) ? raw[i].getContent() : new byte[0];
// msgUnitArr[i] = new MsgUnit(key, cont, raw[i].getQos());
msgUnitArr[i] = new MsgUnit(raw[i], null, new byte[0], null);
}
return msgUnitArr;
}
if (Constants.JDBC_OID.equals(xmlKey.getOid()/*"__sys__jdbc"*/)) { // Query RDBMS !!! hack, we need a general service interface
org.xmlBlaster.protocol.jdbc.XmlDBAdapter adap = new org.xmlBlaster.protocol.jdbc.XmlDBAdapter(glob,
xmlKey.getQueryString().getBytes(), (org.xmlBlaster.protocol.jdbc.NamedConnectionPool)this.glob.getObjectEntry("NamedConnectionPool-"+glob.getId()));
return adap.query();
}
KeyData[] keyDataArr = queryMatchingKeys(sessionInfo, xmlKey, getQos.getData());
ArrayList msgUnitList = new ArrayList(keyDataArr.length);
if (log.isLoggable(Level.FINE)) log.fine("get(): " + ((keyDataArr!=null&&keyDataArr.length>0&&keyDataArr[0]!=null)?"Found local match "+keyDataArr[0].toXml():"No local match"));
// Always forward the get request to the master
// even if there are no matching keys
// In the cluster environment all messages are accessed from the master cluster node,
// tuning with XmlBlasterAccess.synchronousCache is not yet implemented.
if (this.glob.isClusterManagerReady()) { // cluster support - forward erase to master
try {
MsgUnit tmp[] = glob.getClusterManager().forwardGet(sessionInfo, xmlKey, getQos);
if (tmp != null && tmp.length > 0) {
log.info("get() access of " + tmp.length + " messages from cluster master");
for (int jj=0; jj<tmp.length; jj++) {
msgUnitList.add(tmp[jj]);
// We currently don' cache the message here in the slave !!!
// We could do it with the xmlBlasterConnection.initCache(int size)
}
}
}
catch (XmlBlasterException e) {
if (e.getErrorCode() == ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED) {
this.glob.setUseCluster(false);
}
else {
e.printStackTrace();
throw e;
}
}
if (log.isLoggable(Level.FINE)) log.fine("get(): Found " + msgUnitList.size() + " remote matches for " + xmlKey.toXml());
}
NEXT_MSG: for (int ii=0; ii<keyDataArr.length; ii++) {
KeyData xmlKeyExact = keyDataArr[ii];
if (xmlKeyExact == null && xmlKey.isExact()) // subscription on a yet unknown message ...
xmlKeyExact = xmlKey;
TopicHandler topicHandler = this.glob.getTopicAccessor().access(xmlKeyExact.getOid());
if( topicHandler == null ) {
/*
if (this.glob.useCluster()) { // cluster support - forward erase to master
try {
MsgUnit tmp[] = glob.getClusterManager().forwardGet(sessionInfo, xmlKey, getQos);
if (tmp != null && tmp.length > 0) {
log.info(ME, "get() access of " + tmp.length + " messages from cluster master");
for (int jj=0; jj<tmp.length; jj++) {
msgUnitList.add(tmp[jj]);
// We currently don' cache the message here in the slave !!!
// We could do it with the xmlBlasterConnection.initCache(int size)
}
continue NEXT_MSG;
}
}
catch (XmlBlasterException e) {
if (e.getErrorCode() == ErrorCode.RESOURCE_CONFIGURATION_PLUGINFAILED) {
this.glob.setUseCluster(false);
}
else {
e.printStackTrace();
throw e;
}
}
}
*/
if (log.isLoggable(Level.FINE)) log.fine("get(): The key '"+xmlKeyExact.getOid()+"' is not available.");
continue NEXT_MSG;
} // topicHandler==null
try {
if (topicHandler.isAlive()) {
int numEntries = getQos.getHistoryQos().getNumEntries();
MsgUnitWrapper[] msgUnitWrapperArr = topicHandler.getMsgUnitWrapperArr(numEntries, getQos.getHistoryQos().getNewestFirst());
NEXT_HISTORY:
for(int kk=0; kk<msgUnitWrapperArr.length; kk++) {
MsgUnitWrapper msgUnitWrapper = msgUnitWrapperArr[kk];
if (msgUnitWrapper == null) {
continue NEXT_HISTORY;
}
if (this.glob.useCluster() && !msgUnitWrapper.getMsgQosData().isAtMaster()) {
if (log.isLoggable(Level.FINE)) log.fine("get(): Ignore message as we are not the master: " + msgUnitWrapper.toXml());
continue NEXT_HISTORY;
}
//topicHandler.checkFilter(SessionInfo publisherSessionInfo, SubscriptionInfo sub, MsgUnitWrapper msgUnitWrapper, boolean handleException)
AccessFilterQos[] filterQos = getQos.getAccessFilterArr();
if (filterQos != null) {
if (log.isLoggable(Level.FINE)) log.fine("Checking " + filterQos.length + " filters");
for (int jj=0; jj<filterQos.length; jj++) {
I_AccessFilter filter = getAccessPluginManager().getAccessFilter(
filterQos[jj].getType(),
filterQos[jj].getVersion(),
msgUnitWrapper.getContentMime(),
msgUnitWrapper.getContentMimeExtended());
if (log.isLoggable(Level.FINE)) log.fine("get("+xmlKeyExact.getOid()+") filter=" + filter + " qos=" + getQos.toXml());
if (filter != null && filter.match(sessionInfo,
msgUnitWrapper.getMsgUnit(),
filterQos[jj].getQuery()) == false)
continue NEXT_HISTORY; // filtered message is not send to client
}
}
if (msgUnitWrapper.isExpired()) {
continue NEXT_HISTORY;
}
MsgUnit mm = msgUnitWrapper.getMsgUnit();
if (mm == null) {
continue NEXT_HISTORY; // WeakReference to cache lost and lookup failed
}
GetReturnQosServer retQos = new GetReturnQosServer(glob, msgUnitWrapper.getMsgQosData(), Constants.STATE_OK);
byte[] cont = (getQos.getWantContent()) ? mm.getContent() : new byte[0];
mm = new MsgUnit(mm, null, cont, retQos.getData());
msgUnitList.add(mm);
} // for each history entry
} // topicHandler.isAlive()