use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class AuthenticationSwiftletImpl method createRLGroups.
private void createRLGroups(EntityList groupList) throws SwiftletException {
if (traceSpace.enabled)
traceSpace.trace(getName(), "creating resource limit groups ...");
Map m = groupList.getEntities();
Entity pgEntity = (Entity) m.get(PUBLIC_GROUP);
if (pgEntity == null) {
pgEntity = groupList.createEntity();
pgEntity.setName(PUBLIC_GROUP);
pgEntity.createCommands();
try {
groupList.addEntity(pgEntity);
} catch (Exception e) {
throw new SwiftletException(e.toString());
}
m = groupList.getEntities();
}
if (m.size() > 0) {
for (Iterator iter = m.keySet().iterator(); iter.hasNext(); ) {
String groupName = (String) iter.next();
Entity groupEntity = groupList.getEntity(groupName);
createRLGroup(groupName, groupEntity);
}
}
// Ensure to have always a public group
if (publicRLGroup == null) {
publicRLGroup = new ResourceLimitGroup(PUBLIC_GROUP, -1, 10, 10, 10, 10);
rlgroups.put(PUBLIC_GROUP, publicRLGroup);
}
groupList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
String groupName = newEntity.getName();
try {
createRLGroup(groupName, newEntity);
if (traceSpace.enabled)
traceSpace.trace(getName(), "onEntityAdd (resource limit group): new group=" + groupName);
} catch (SwiftletException e) {
throw new EntityAddException(e.getMessage());
}
}
});
groupList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
String groupName = delEntity.getName();
if (groupName.equals(PUBLIC_GROUP))
throw new EntityRemoveException("Can't remove 'public' Resource Limit Group.");
List ulist = getUsersForRLGroup((ResourceLimitGroup) rlgroups.get(groupName));
if (ulist != null) {
StringBuffer b = new StringBuffer();
b.append("Can't remove Resource Limit Group; it's assigned to User(s) ");
for (int i = 0; i < ulist.size(); i++) {
if (i > 0)
b.append(", ");
b.append(((User) ulist.get(i)).getName());
}
throw new EntityRemoveException(b.toString());
}
if (traceSpace.enabled)
traceSpace.trace(getName(), "onEntityRemove (resource limit group): del group=" + groupName);
rlgroups.remove(groupName);
}
});
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class AuthenticationSwiftletImpl method createRLGroup.
private ResourceLimitGroup createRLGroup(String groupName, Entity groupEntity) throws SwiftletException {
if (rlgroups.get(groupName) != null)
throw new SwiftletException("Resource Limit Group '" + groupName + "' is already defined!");
Property maxConnectionsProp = groupEntity.getProperty("max-connections");
Property maxSessionsProp = groupEntity.getProperty("max-sessions");
Property maxTempQueuesProp = groupEntity.getProperty("max-tempqueues");
Property maxProducersProp = groupEntity.getProperty("max-producers");
Property maxConsumersProp = groupEntity.getProperty("max-consumers");
ResourceLimitGroup group = new ResourceLimitGroup(groupName, ((Integer) maxConnectionsProp.getValue()).intValue(), ((Integer) maxSessionsProp.getValue()).intValue(), ((Integer) maxTempQueuesProp.getValue()).intValue(), ((Integer) maxProducersProp.getValue()).intValue(), ((Integer) maxConsumersProp.getValue()).intValue());
maxConnectionsProp.setPropertyChangeListener(new PropertyChangeAdapter(group) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ResourceLimitGroup myGroup = (ResourceLimitGroup) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (max connections): resource limit group=" + myGroup + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGroup.setMaxConnections(((Integer) newValue).intValue());
}
});
maxSessionsProp.setPropertyChangeListener(new PropertyChangeAdapter(group) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ResourceLimitGroup myGroup = (ResourceLimitGroup) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (max sessions): resource limit group=" + myGroup + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGroup.setMaxSessions(((Integer) newValue).intValue());
}
});
maxTempQueuesProp.setPropertyChangeListener(new PropertyChangeAdapter(group) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ResourceLimitGroup myGroup = (ResourceLimitGroup) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (max temp queues): resource limit group=" + myGroup + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGroup.setMaxTempQueues(((Integer) newValue).intValue());
}
});
maxProducersProp.setPropertyChangeListener(new PropertyChangeAdapter(group) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ResourceLimitGroup myGroup = (ResourceLimitGroup) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (max producers): resource limit group=" + myGroup + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGroup.setMaxProducers(((Integer) newValue).intValue());
}
});
maxConsumersProp.setPropertyChangeListener(new PropertyChangeAdapter(group) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
ResourceLimitGroup myGroup = (ResourceLimitGroup) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (max consumers): resource limit group=" + myGroup + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGroup.setMaxConsumers(((Integer) newValue).intValue());
}
});
if (traceSpace.enabled)
traceSpace.trace(getName(), "createResourceLimitGroup: " + group);
rlgroups.put(group.getName(), group);
if (group.getName().equals(PUBLIC_GROUP))
publicRLGroup = group;
return group;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class AuthenticationSwiftletImpl method createUser.
private User createUser(String userName, Entity userEntity) throws SwiftletException {
if (users.get(userName) != null)
throw new SwiftletException("User '" + userName + "' is already defined!");
Property groupProp = userEntity.getProperty("group");
String groupName = (String) groupProp.getValue();
Group group = (Group) groups.get(groupName);
if (group == null)
throw new SwiftletException("User '" + userName + "', group '" + groupName + "' is unknown!");
Property rlgroupProp = userEntity.getProperty("resource-limit-group");
String rlgroupName = (String) rlgroupProp.getValue();
ResourceLimitGroup rlgroup = (ResourceLimitGroup) rlgroups.get(rlgroupName);
if (rlgroup == null)
throw new SwiftletException("User '" + userName + "', resource limit group '" + rlgroupName + "' is unknown!");
Property passwProp = userEntity.getProperty("password");
String password = (String) passwProp.getValue();
User user = new User(userName, password, group, rlgroup);
EntityList gh = (EntityList) userEntity.getEntity("host-access-list");
createHostAccessList(user, gh);
if (traceSpace.enabled)
traceSpace.trace(getName(), "createUser: " + user);
users.put(user.getName(), user);
groupProp.setPropertyChangeListener(new PropertyChangeAdapter(user) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
User myUser = (User) configObject;
Group myGroup = (Group) groups.get(newValue);
if (myGroup == null)
throw new PropertyChangeException("Group '" + (String) newValue + "' is unknown!");
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (group): user=" + myUser + ", oldValue=" + oldValue + ", newValue=" + newValue);
myUser.setGroup(myGroup);
}
});
rlgroupProp.setPropertyChangeListener(new PropertyChangeAdapter(user) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
User myUser = (User) configObject;
ResourceLimitGroup myGroup = (ResourceLimitGroup) rlgroups.get(newValue);
if (myGroup == null)
throw new PropertyChangeException("Resource Limit Group '" + (String) newValue + "' is unknown!");
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (resource limit group): user=" + myUser + ", oldValue=" + oldValue + ", newValue=" + newValue);
myUser.setResourceLimitGroup(myGroup);
}
});
passwProp.setPropertyChangeListener(new PropertyChangeAdapter(user) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
User myUser = (User) configObject;
String myPassword = (String) newValue;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (password): user=" + myUser + ", oldValue=" + oldValue + ", newValue=" + newValue);
myUser.setPassword(myPassword);
}
});
return user;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class AuthenticationSwiftletImpl method createQueueGrant.
private QueueResourceGrant createQueueGrant(Group group, Entity queueGrantEntity) throws SwiftletException {
String queueName = queueGrantEntity.getName();
try {
SwiftUtilities.verifyQueueName(queueName);
if (queueName.indexOf('@') == -1)
queueName += '@' + SwiftletManager.getInstance().getRouterName();
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
Property pSend = queueGrantEntity.getProperty("send-grant");
boolean send = ((Boolean) pSend.getValue()).booleanValue();
Property pRcv = queueGrantEntity.getProperty("receive-grant");
boolean receive = ((Boolean) pRcv.getValue()).booleanValue();
Property pBrowse = queueGrantEntity.getProperty("browse-grant");
boolean browse = ((Boolean) pBrowse.getValue()).booleanValue();
QueueResourceGrant grant = new QueueResourceGrant(queueName, receive, send, browse);
group.addQueueResourceGrant(grant);
pSend.setPropertyChangeListener(new PropertyChangeAdapter(grant) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
QueueResourceGrant myGrant = (QueueResourceGrant) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (send grant): grant=" + myGrant + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGrant.setSenderGranted(((Boolean) newValue).booleanValue());
}
});
pRcv.setPropertyChangeListener(new PropertyChangeAdapter(grant) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
QueueResourceGrant myGrant = (QueueResourceGrant) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (receive grant): grant=" + myGrant + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGrant.setReceiverGranted(((Boolean) newValue).booleanValue());
}
});
pBrowse.setPropertyChangeListener(new PropertyChangeAdapter(grant) {
public void propertyChanged(Property property, Object oldValue, Object newValue) throws PropertyChangeException {
QueueResourceGrant myGrant = (QueueResourceGrant) configObject;
if (traceSpace.enabled)
traceSpace.trace(getName(), "propertyChanged (browse grant): grant=" + myGrant + ", oldValue=" + oldValue + ", newValue=" + newValue);
myGrant.setBrowserGranted(((Boolean) newValue).booleanValue());
}
});
return grant;
}
use of com.swiftmq.swiftlet.SwiftletException in project swiftmq-ce by iitsoftware.
the class TopicManagerImpl method startup.
protected void startup(Configuration config) throws SwiftletException {
this.config = config;
root = config;
ctx = new TopicManagerContext();
ctx.topicManager = this;
ctx.traceSwiftlet = (TraceSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$trace");
ctx.traceSpace = ctx.traceSwiftlet.getTraceSpace(TraceSwiftlet.SPACE_KERNEL);
ctx.logSwiftlet = (LogSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$log");
ctx.storeSwiftlet = (StoreSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$store");
ctx.queueManager = (QueueManager) SwiftletManager.getInstance().getSwiftlet("sys$queuemanager");
ctx.authSwiftlet = (AuthenticationSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$authentication");
ctx.threadpoolSwiftlet = (ThreadpoolSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$threadpool");
ctx.timerSwiftlet = (TimerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$timer");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup ...");
ctx.activeDurableList = (EntityList) root.getEntity("usage").getEntity("durables");
ctx.activeSubscriberList = (EntityList) root.getEntity("usage").getEntity("subscriber");
ctx.remoteSubscriberList = (EntityList) root.getEntity("usage").getEntity("subscriber-remote");
if (ctx.remoteSubscriberList != null) {
ctx.remoteSubscriberList.setEntityRemoveListener(new EntityRemoveListener() {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
removeRemoteSubscriptions(delEntity.getName());
if (ctx.announceSender != null)
ctx.announceSender.routerRemoved(delEntity.getName());
}
});
new TopicAnnounceSender(ctx);
}
SwiftletManager.getInstance().addSwiftletManagerListener("sys$routing", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.routingSwiftlet = (RoutingSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$routing");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting topic announcer ...");
Route[] routes = ctx.routingSwiftlet.getRoutes();
if (routes != null) {
for (int i = 0; i < routes.length; i++) {
ctx.announceSender.destinationAdded(routes[i]);
}
}
ctx.routingSwiftlet.addRoutingListener(ctx.announceSender);
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
ctx.announceSender.start();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating static remote subscriptions ...");
try {
createStaticRemoteRouterSubs();
} catch (SwiftletException e) {
e.printStackTrace();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating static remote subscriptions ...");
ctx.logSwiftlet.logError("sys$topicmanager", e.getMessage());
}
}
});
SwiftletManager.getInstance().addSwiftletManagerListener("sys$jndi", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent evt) {
try {
ctx.jndiSwiftlet = (JNDISwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$jndi");
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "registering JNDI topics ...");
Iterator iter = rootBrokers.entrySet().iterator();
while (iter.hasNext()) {
TopicBroker broker = (TopicBroker) ((Map.Entry) iter.next()).getValue();
String[] names = broker.getTopicNames();
for (int i = 0; i < names.length; i++) {
registerJNDI(names[i], new TopicImpl(names[i]));
}
}
} catch (Exception e) {
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "swiftletStartet, exception=" + e);
}
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup: creating topics ...");
ctx.logSwiftlet.logInformation(getName(), "startup: creating topics ...");
try {
createTopics((EntityList) root.getEntity("topics"));
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
if (ctx.remoteSubscriberList != null) {
topicQueue = TOPIC_QUEUE + '@' + SwiftletManager.getInstance().getRouterName();
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "starting TopicAnnounceReceiver ...");
try {
new TopicAnnounceReceiver(ctx, topicQueue);
} catch (Exception e) {
throw new SwiftletException(e.getMessage());
}
}
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating durable subscribers ... ");
try {
durableSubscriptions = loadDurables();
} catch (Exception e) {
throw new SwiftletException("error loading durable subscriptions: " + e);
}
Iterator iter = durableSubscriptions.keySet().iterator();
while (iter.hasNext()) {
String queueName = (String) iter.next();
DurableSubscription durable = (DurableSubscription) durableSubscriptions.get(queueName);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "creating durable subscriber: " + durable);
durableSubscriptions.put(durable.getQueueName(), durable);
try {
ctx.queueManager.createQueue(durable.getQueueName(), (ActiveLogin) null);
TopicImpl topic = new TopicImpl(getQueueForTopic(durable.getTopicName()), durable.getTopicName());
// it could be the topic isn't defined but it MUST for dursubs!
try {
createTopic(topic.getTopicName());
} catch (Exception ignored) {
}
ActiveLogin dlogin = ctx.authSwiftlet.createActiveLogin(durable.getClientId(), DURABLE_TYPE);
dlogin.setClientId(durable.getClientId());
int id = subscribe(topic, durable.getSelector(), durable.isNoLocal(), durable.getQueueName(), dlogin);
durable.setTopicSubscription((TopicSubscription) topicSubscriptions.get(id));
Entity durEntity = ctx.activeDurableList.createEntity();
durEntity.setName(durable.getQueueName());
durEntity.setDynamicObject(durable);
durEntity.createCommands();
Property prop = durEntity.getProperty("clientid");
prop.setValue(dlogin.getClientId());
prop.setReadOnly(true);
prop = durEntity.getProperty("durablename");
prop.setValue(durable.getDurableName());
prop.setReadOnly(true);
prop = durEntity.getProperty("topic");
prop.setValue(durable.getTopicName());
prop.setReadOnly(true);
prop = durEntity.getProperty("boundto");
prop.setValue(durable.getQueueName());
prop.setReadOnly(true);
prop = durEntity.getProperty("nolocal");
prop.setValue(new Boolean(durable.isNoLocal()));
prop.setReadOnly(true);
prop = durEntity.getProperty("selector");
if (durable.getSelector() != null) {
prop.setValue(durable.getSelector().getConditionString());
}
prop.setReadOnly(true);
ctx.activeDurableList.addEntity(durEntity);
} catch (Exception e) {
e.printStackTrace();
throw new SwiftletException(e.getMessage());
}
}
ctx.activeDurableList.setEntityAddListener(new EntityChangeAdapter(null) {
public void onEntityAdd(Entity parent, Entity newEntity) throws EntityAddException {
try {
if (programmaticDurableInProgress)
// do nothing
return;
String clientId = (String) newEntity.getProperty("clientid").getValue();
SwiftUtilities.verifyClientId(clientId);
String durableName = (String) newEntity.getProperty("durablename").getValue();
SwiftUtilities.verifyDurableName(durableName);
if (!newEntity.getName().equals(clientId + "$" + durableName))
throw new Exception("The name of this entity must be: " + clientId + "$" + durableName + " (but it is " + newEntity.getName() + ")");
if (clientId.indexOf('@') == -1) {
clientId = clientId + "@" + SwiftletManager.getInstance().getRouterName();
newEntity.getProperty("clientid").setValue(clientId);
}
String sel = (String) newEntity.getProperty("selector").getValue();
MessageSelector selector = null;
if (sel != null) {
selector = new MessageSelector(sel);
selector.compile();
}
String topicName = (String) newEntity.getProperty("topic").getValue();
if (!isTopicDefined(topicName))
throw new Exception("Unknown topic: " + topicName);
TopicImpl topic = verifyTopic(new TopicImpl(topicName));
boolean noLocal = ((Boolean) newEntity.getProperty("nolocal").getValue()).booleanValue();
ActiveLogin dlogin = ctx.authSwiftlet.createActiveLogin(clientId, DURABLE_TYPE);
dlogin.setClientId(clientId);
subscribeDurable(durableName, topic, selector, noLocal, dlogin, newEntity, false);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityAdd (durable): new durable=" + newEntity.getName());
} catch (Exception e) {
throw new EntityAddException(e.getMessage());
}
}
});
ctx.activeDurableList.setEntityRemoveListener(new EntityChangeAdapter(null) {
public void onEntityRemove(Entity parent, Entity delEntity) throws EntityRemoveException {
try {
DurableSubscription myDurable = (DurableSubscription) delEntity.getDynamicObject();
ActiveLogin myLogin = ctx.authSwiftlet.createActiveLogin(myDurable.getClientId(), "DURABLE");
myLogin.setClientId(myDurable.getClientId());
deleteDurable(myDurable.getDurableName(), myLogin);
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "onEntityRemove (durable): del durable=" + myDurable);
} catch (Exception e) {
throw new EntityRemoveException(e.getMessage());
}
}
});
createSlowSubscriberConditions();
SwiftletManager.getInstance().addSwiftletManagerListener("sys$scheduler", new SwiftletManagerAdapter() {
public void swiftletStarted(SwiftletManagerEvent event) {
jobRegistrar = new JobRegistrar(TopicManagerImpl.this, (SchedulerSwiftlet) SwiftletManager.getInstance().getSwiftlet("sys$scheduler"), ctx);
jobRegistrar.register();
}
public void swiftletStopInitiated(SwiftletManagerEvent event) {
jobRegistrar.unregister();
}
});
if (ctx.traceSpace.enabled)
ctx.traceSpace.trace(getName(), "startup done.");
}
Aggregations