use of com.sun.messaging.jmq.jmsserver.core.ProducerUID in project openmq by eclipse-ee4j.
the class ProducerHandler method handle.
/**
* Method to handle Producers
*/
@Override
public boolean handle(IMQConnection con, Packet msg) throws BrokerException {
Packet reply = new Packet(con.useDirectBuffers());
reply.setPacketType(msg.getPacketType() + 1);
reply.setConsumerID(msg.getConsumerID());
boolean isIndemp = msg.getIndempotent();
int status = Status.OK;
String reason = null;
Hashtable props = null;
try {
props = msg.getProperties();
} catch (Exception ex) {
throw new RuntimeException("Can not load props", ex);
}
Hashtable returnprop = new Hashtable();
Destination d = null;
try {
if (msg.getPacketType() == PacketType.ADD_PRODUCER) {
String dest = (String) props.get("JMQDestination");
Integer type = (Integer) props.get("JMQDestType");
if (!con.isAdminConnection() && MemoryGlobals.getMEM_DISALLOW_PRODUCERS()) {
status = Status.ERROR;
reason = "Low memory";
logger.log(Logger.WARNING, BrokerResources.W_LOW_MEM_REJECT_PRODUCER);
throw new BrokerException(reason, status);
}
Long lsessionid = (Long) props.get("JMQSessionID");
if (lsessionid != null) {
// 3.5 protocol
SessionUID sessionID = new SessionUID(lsessionid.longValue());
// single threaded .. we dont have to worry about
// someone else creating it
Session session = con.getSession(sessionID);
if (session == null) {
throw new BrokerException("Internal Error: client sent " + "invalid sessionUID w/ ADD_PRODUCER " + sessionID + " session does not exist");
}
}
Destination[] ds = null;
DestinationUID duid = null;
if (dest != null && !DestinationUID.isWildcard(dest) && type != null) {
while (true) {
ds = DL.getDestination(con.getPartitionedStore(), dest, type.intValue(), true, !con.isAdminConnection());
d = ds[0];
if (d != null) {
try {
d.incrementRefCount();
} catch (BrokerException ex) {
// try again
continue;
} catch (IllegalStateException ex) {
throw new BrokerException(Globals.getBrokerResources().getKString(BrokerResources.X_SHUTTING_DOWN_BROKER), BrokerResources.X_SHUTTING_DOWN_BROKER, ex, Status.ERROR);
}
}
// got a lock on the dest
break;
}
if (d == null) {
logger.log(Logger.DEBUG, "Unable to add " + "producer to " + dest + " :" + DestType.toString(type.intValue()) + " destination can not be autocreated ");
reason = "can not create destination";
status = Status.NOT_FOUND;
throw new BrokerException(reason, status);
}
duid = d.getDestinationUID();
} else if (dest == null || type == null) {
reason = "no destination passed [dest,type] = [" + dest + "," + type + "]";
status = Status.ERROR;
throw new BrokerException(reason, status);
} else {
duid = DestinationUID.getUID(dest, DestType.isQueue(type.intValue()));
}
String info = msg.getSysMessageID().toString();
Producer p = addProducer(duid, con, info, isIndemp);
ProducerUID pid = p.getProducerUID();
assert pid != null;
// LKS - XXX - REVISIT - WHAT ABOUT FLOW CONTROL
boolean active = d == null || d.isProducerActive(pid);
returnprop.put("JMQProducerID", Long.valueOf(pid.longValue()));
returnprop.put("JMQDestinationID", duid.toString());
if (d == null) {
returnprop.put("JMQBytes", Long.valueOf(-1));
returnprop.put("JMQSize", Integer.valueOf(-1));
} else if (active) {
returnprop.put("JMQBytes", Long.valueOf(d.getBytesProducerFlow()));
returnprop.put("JMQSize", Integer.valueOf(d.getSizeProducerFlow()));
} else {
returnprop.put("JMQBytes", Long.valueOf(0));
returnprop.put("JMQSize", Integer.valueOf(0));
}
} else {
assert msg.getPacketType() == PacketType.DELETE_PRODUCER;
Long pid_l = (Long) props.get("JMQProducerID");
ProducerUID pid = new ProducerUID(pid_l == null ? 0 : pid_l.longValue());
removeProducer(pid, isIndemp, con, "Producer closed requested:\n\tconnection: " + con.getConnectionUID() + "\n\tproducerID: " + pid + "\n\trequest sysmsgid message: " + msg.getSysMessageID());
}
} catch (BrokerException ex) {
status = ex.getStatusCode();
reason = ex.getMessage();
logger.log(Logger.INFO, reason);
} catch (Exception ex) {
logger.logStack(Logger.INFO, BrokerResources.E_INTERNAL_BROKER_ERROR, "producer message ", ex);
reason = ex.getMessage();
status = Status.ERROR;
} finally {
if (d != null) {
d.decrementRefCount();
}
}
returnprop.put("JMQStatus", Integer.valueOf(status));
if (reason != null) {
returnprop.put("JMQReason", reason);
}
if (((IMQBasicConnection) con).getDumpPacket() || ((IMQBasicConnection) con).getDumpOutPacket()) {
returnprop.put("JMQReqID", msg.getSysMessageID().toString());
}
reply.setProperties(returnprop);
con.sendControlMessage(reply);
return true;
}
use of com.sun.messaging.jmq.jmsserver.core.ProducerUID in project openmq by eclipse-ee4j.
the class JMSServiceImpl method deleteProducer.
/**
* Delete a producer.
*
* @param connectionId The Id of the connection in which to delete the producer
* @param sessionId The Id of the session in which to delete the producer
* @param producerId The Id of the producer to delete
*
* @return The JMSServiceReply of the request to delete a producer
*
* @throws JMSServiceException if the Status returned for the deleteProducer method is not
* {@link JMSServiceReply.Status#OK}
*
* @see JMSServiceReply.Status#FORBIDDEN
* @see JMSServiceReply.Status#NOT_FOUND
* @see JMSServiceReply.Status#ERROR
*/
@Override
public JMSServiceReply deleteProducer(long connectionId, long sessionId, long producerId) throws JMSServiceException {
JMSServiceReply reply;
HashMap props = new HashMap();
IMQConnection cxn;
cxn = checkConnectionId(connectionId, "deleteProducer");
try {
protocol.removeProducer(new ProducerUID(producerId), cxn, new Object().toString());
} catch (Exception e) {
String errStr = "deleteProducer: Delete producer failed. Connection ID: " + connectionId + ", session ID: " + sessionId + ", producer ID: " + producerId;
logger.logStack(Logger.ERROR, errStr, e);
props.put("JMQStatus", getErrorReplyStatus(e));
throw new JMSServiceException(errStr, e, props);
}
props.put("JMQStatus", JMSServiceReply.Status.OK);
reply = new JMSServiceReply(props);
return (reply);
}
use of com.sun.messaging.jmq.jmsserver.core.ProducerUID in project openmq by eclipse-ee4j.
the class ServiceMonitor method getProducerIDs.
public String[] getProducerIDs() throws MBeanException {
List producerIDs = ServiceUtil.getProducerIDs(service);
String[] ids;
if ((producerIDs == null) || (producerIDs.size() == 0)) {
return (null);
}
ids = new String[producerIDs.size()];
Iterator iter = producerIDs.iterator();
int i = 0;
while (iter.hasNext()) {
ProducerUID pid = (ProducerUID) iter.next();
long prdID = pid.longValue();
String id;
try {
id = Long.toString(prdID);
ids[i] = id;
} catch (Exception ex) {
handleOperationException(ServiceOperations.GET_PRODUCER_IDS, ex);
}
i++;
}
return (ids);
}
use of com.sun.messaging.jmq.jmsserver.core.ProducerUID in project openmq by eclipse-ee4j.
the class ProducerManagerMonitor method getProducerWildcards.
public String[] getProducerWildcards() throws MBeanException {
ArrayList<String> al = new ArrayList<>();
String[] list = null;
int numWildcardProducers = Producer.getNumWildcardProducers();
Iterator producers;
if (numWildcardProducers <= 0) {
return (null);
}
producers = Producer.getWildcardProducers();
if (producers == null) {
return (null);
}
while (producers.hasNext()) {
ProducerUID pid = (ProducerUID) producers.next();
Producer oneProd = (Producer) Producer.getProducer(pid);
DestinationUID id = oneProd.getDestinationUID();
al.add(id.getName());
}
if (al.size() > 0) {
list = new String[al.size()];
list = al.toArray(list);
}
return (list);
}
use of com.sun.messaging.jmq.jmsserver.core.ProducerUID in project openmq by eclipse-ee4j.
the class ConnectionMonitor method getProducerIDs.
public String[] getProducerIDs() throws MBeanException {
List producerIDs = ConnectionUtil.getProducerIDs(id);
String[] ids;
if ((producerIDs == null) || (producerIDs.size() == 0)) {
return (null);
}
ids = new String[producerIDs.size()];
Iterator iter = producerIDs.iterator();
int i = 0;
while (iter.hasNext()) {
ProducerUID pid = (ProducerUID) iter.next();
long prdID = pid.longValue();
String id;
try {
id = Long.toString(prdID);
ids[i] = id;
} catch (Exception ex) {
handleOperationException(ConnectionOperations.GET_PRODUCER_IDS, ex);
}
i++;
}
return (ids);
}
Aggregations