Author: mladen.turk(a)jboss.com
Date: 2008-05-28 11:47:01 -0400 (Wed, 28 May 2008)
New Revision: 1630
Added:
sandbox/aloha/java/
sandbox/aloha/java/org/
sandbox/aloha/java/org/jboss/
sandbox/aloha/java/org/jboss/aloha/
sandbox/aloha/java/org/jboss/aloha/AdvertiseMode.java
sandbox/aloha/java/org/jboss/aloha/Application.java
sandbox/aloha/java/org/jboss/aloha/ApplicationPool.java
sandbox/aloha/java/org/jboss/aloha/Balancer.java
sandbox/aloha/java/org/jboss/aloha/BalancerMethod.java
sandbox/aloha/java/org/jboss/aloha/BooleanType.java
sandbox/aloha/java/org/jboss/aloha/Command.java
sandbox/aloha/java/org/jboss/aloha/Default.java
sandbox/aloha/java/org/jboss/aloha/GenericResource.java
sandbox/aloha/java/org/jboss/aloha/Globals.java
sandbox/aloha/java/org/jboss/aloha/Host.java
sandbox/aloha/java/org/jboss/aloha/HttpMessage.java
sandbox/aloha/java/org/jboss/aloha/InvalidValueException.java
sandbox/aloha/java/org/jboss/aloha/ManagedServer.java
sandbox/aloha/java/org/jboss/aloha/Manager.java
sandbox/aloha/java/org/jboss/aloha/Member.java
sandbox/aloha/java/org/jboss/aloha/MemberApplication.java
sandbox/aloha/java/org/jboss/aloha/Message.java
sandbox/aloha/java/org/jboss/aloha/MessageFactory.java
sandbox/aloha/java/org/jboss/aloha/MessageProtocol.java
sandbox/aloha/java/org/jboss/aloha/Parameter.java
sandbox/aloha/java/org/jboss/aloha/ParameterType.java
sandbox/aloha/java/org/jboss/aloha/ParameterUpdateCallback.java
sandbox/aloha/java/org/jboss/aloha/ProtocolType.java
sandbox/aloha/java/org/jboss/aloha/Resource.java
sandbox/aloha/java/org/jboss/aloha/ResourceType.java
sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
sandbox/aloha/java/org/jboss/aloha/ResponseType.java
sandbox/aloha/java/org/jboss/aloha/Server.java
sandbox/aloha/java/org/jboss/aloha/StateMode.java
sandbox/aloha/java/org/jboss/aloha/advertise/
sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseEventType.java
sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseListener.java
sandbox/aloha/java/org/jboss/aloha/advertise/AdvertisedServer.java
sandbox/aloha/java/org/jboss/aloha/advertise/IAdvertiseEvent.java
sandbox/aloha/java/org/jboss/aloha/util/
sandbox/aloha/java/org/jboss/aloha/util/Base64.java
sandbox/aloha/java/org/jboss/aloha/util/Utils.java
sandbox/aloha/java/overview.html
Log:
Add core java classes
Added: sandbox/aloha/java/org/jboss/aloha/AdvertiseMode.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/AdvertiseMode.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/AdvertiseMode.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,48 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * AdvertiseMode enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum AdvertiseMode
+{
+ On,
+ Off,
+ Status;
+
+ public static AdvertiseMode valueOfIgnoreCase(String name)
+ {
+ for (AdvertiseMode e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ throw new IllegalArgumentException("Invalid initializer: " + name);
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/AdvertiseMode.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Application.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Application.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Application.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,90 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Application resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Application extends Resource
+{
+
+ public Parameter Host = addParameter("Host",
true, ParameterType.Resource);
+ public Parameter ApplicationPool =
addParameter("ApplicationPool", false, ParameterType.Resource);
+ public Parameter State = addParameter("State",
false, ParameterType.State);
+ public Parameter Status = addParameter("Status",
false, ParameterType.State);
+
+ public ResourceType getResourceType() { return ResourceType.Application; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return Host.getResource(); }
+
+ private String resourceName;
+
+ private Application()
+ {
+ // Disable creation of unnamed resource
+ }
+
+ public Application(Host host, String name)
+ {
+ super(host.getManagedServer());
+ resourceName = name;
+ if (host != null) {
+ // Reference this Application to the Host
+ host.addApplication(this);
+ try {
+ Host.setValue(host);
+ } catch (Exception e) {
+ // Ignore
+ }
+ try {
+ for (Member m : ((Balancer)host.Balancer.getResource()).getMembers()) {
+ m.addApplication(this);
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+
+ protected Application(ManagedServer managedServer, String name)
+ {
+ this((Host)managedServer.getResource(ResourceType.Host), name);
+ }
+
+ public void onUpdateResource(Parameter p, Resource ov, Resource nv)
+ {
+ if (nv.getResourceType() == ResourceType.ApplicationPool) {
+ // Changing ApplicationPool
+ }
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Application.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ApplicationPool.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ApplicationPool.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/ApplicationPool.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * ApplicationPool resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class ApplicationPool extends Resource
+{
+ public Parameter Status = addParameter("Status",
false, ParameterType.State);
+ public Parameter Busy = addParameter("Busy",
true, ParameterType.Integer);
+ public Parameter Concurrency = addParameter("Concurrency",
false, ParameterType.Integer);
+ public Parameter TimeOut = addParameter("TimeOut",
false, ParameterType.Long);
+ public Parameter Applications = addParameter("Applications",
true, ParameterType.Integer);
+
+
+ public ResourceType getResourceType() { return ResourceType.ApplicationPool; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+
+ private String resourceName;
+
+ private ApplicationPool()
+ {
+ // Disable creation of unlinked resource
+ }
+
+ public ApplicationPool(ManagedServer managedServer, String name)
+ {
+ super(managedServer);
+ resourceName = name;
+ }
+
+ public ApplicationPool(ManagedServer managedServer)
+ {
+ this(managedServer, Default.NAME);
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ApplicationPool.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Balancer.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Balancer.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Balancer.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,120 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Balancer resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Balancer extends Resource
+{
+ public Parameter Status = addParameter("Status",
false, ParameterType.State);
+ public Parameter StickySession = addParameter("StickySession",
false, ParameterType.Boolean);
+ public Parameter StickySessionCookie =
addParameter("StickySessionCookie", false, ParameterType.String);
+ public Parameter StickySessionPath =
addParameter("StickySessionPath", false, ParameterType.String);
+ public Parameter StickySessionRemove =
addParameter("StickySessionRemove", false, ParameterType.Boolean);
+ public Parameter StickySessionForce =
addParameter("StickySessionForce", false, ParameterType.Boolean);
+ public Parameter TimeOut = addParameter("TimeOut",
false, ParameterType.Long);
+ public Parameter MaxFailoverAttempts =
addParameter("MaxFailoverAttempts", false, ParameterType.Integer);
+ public Parameter AbortIfHeadersSend =
addParameter("AbortIfHeadersSend", false, ParameterType.Boolean);
+ public Parameter AbortIfResponseReceived =
addParameter("AbortIfResponseReceived",false, ParameterType.Boolean);
+ public Parameter InterstageMethod =
addParameter("InterstageMethod", false, ParameterType.BalancerMethod);
+
+
+ public ResourceType getResourceType() { return ResourceType.Balancer; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+ private ManagedServer managedServer;
+
+ private String resourceName;
+ private HashMap<String, Member> memberMap;
+ private HashMap<String, Host> hostMap;
+
+
+ public Collection<Member> getMembers()
+ {
+ return memberMap.values();
+ }
+
+ public void addMember(Member member)
+ {
+ memberMap.put(member.getResourceName(), member);
+ }
+
+ public Member getMember(String name)
+ {
+ return memberMap.get(name);
+ }
+
+ public void removeMember(Member member)
+ {
+ memberMap.remove(member);
+ }
+
+ public Collection<Host> getHosts()
+ {
+ return hostMap.values();
+ }
+
+ public void addHost(Host host)
+ {
+ hostMap.put(host.getResourceName(), host);
+ }
+
+ public Host getHost(String name)
+ {
+ return hostMap.get(name);
+ }
+
+ public void removeHost(Host host)
+ {
+ hostMap.remove(host);
+ }
+
+ private Balancer()
+ {
+ // Disable creation of unlinked resource
+ }
+
+ protected Balancer(ManagedServer managedServer, String name)
+ {
+ super(managedServer);
+ resourceName = name;
+ memberMap = new HashMap<String, Member>();
+ hostMap = new HashMap<String, Host>();
+ }
+
+ protected Balancer(ManagedServer managedServer)
+ {
+ this(managedServer, Default.NAME);
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Balancer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/BalancerMethod.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/BalancerMethod.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/BalancerMethod.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,60 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * BalancerMethod enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum BalancerMethod
+{
+ Unknown( "-"),
+ RoundRobin( "R"),
+ Busyness( "B");
+
+ private String value;
+ private BalancerMethod(String v)
+ {
+ value = v;
+ }
+
+ public String valueOf()
+ {
+ return value;
+ }
+
+ public static BalancerMethod valueOfIgnoreCase(String name)
+ {
+ for (BalancerMethod e : values()) {
+ if (e.value.equalsIgnoreCase(name))
+ return e;
+ else if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ return BalancerMethod.Unknown;
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/BalancerMethod.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/BooleanType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/BooleanType.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/BooleanType.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * BooleanType enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum BooleanType
+{
+ Yes( true),
+ No( false),
+ Y( true),
+ N( false),
+ On( true),
+ Off( false),
+ True( true),
+ False( false);
+
+ private boolean value;
+ private BooleanType(boolean v)
+ {
+ value = v;
+ }
+
+ public boolean valueOf()
+ {
+ return value;
+ }
+
+ public static BooleanType valueOfIgnoreCase(String name)
+ {
+ for (BooleanType e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ if (Long.parseLong(name) == 0)
+ return BooleanType.False;
+ else
+ return BooleanType.True;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/BooleanType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Command.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Command.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Command.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * Command type enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum Command
+{
+ Info,
+ Enable,
+ Disable,
+ Stop,
+ Delete,
+ Config,
+ Exec,
+ Reset;
+
+ public static Command valueOfIgnoreCase(String name)
+ {
+ for (Command e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ throw new IllegalArgumentException("Invalid initializer: " + name);
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Command.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Default.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Default.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Default.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,51 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * Default values
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Default
+{
+
+ /** Default charset used for protocol messages */
+ public static final String CHARSET = "8859_1";
+ public static final String MANAGER_URL = "/server-manager";
+ public static final String NAME = "_default_";
+
+ public static int CONNECT_TIMEOUT = 1000;
+ public static int READ_TIMEOUT = 2000;
+
+ public static final long MANAGER_ID = 1L;
+ public static final long SERVER_ID = 2L;
+
+ private Default()
+ {
+ // Disable creation
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Default.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/GenericResource.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/GenericResource.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/GenericResource.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,74 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Generic resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class GenericResource extends Resource
+{
+
+ private ResourceType resourceType = ResourceType.Unknown;
+ private String resourceName;
+
+ public ResourceType getResourceType() { return resourceType; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+ private ManagedServer managedServer;
+
+ public void setResourceType(ResourceType v) { resourceType = v; }
+ public void setResourceName(String v) { resourceName = v; }
+
+ public GenericResource(ManagedServer managedServer, String name)
+ {
+ resourceName = name;
+ this.managedServer = managedServer;
+ }
+
+ public GenericResource(ManagedServer managedServer)
+ {
+ this(managedServer, ResourceType.Unknown.toString());
+ }
+
+ public GenericResource()
+ {
+ this(null);
+ }
+
+ public void addParameter(String name, String value)
+ {
+ Parameter p = new Parameter(name, value);
+ addParameter(p);
+ }
+
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/GenericResource.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Globals.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Globals.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Globals.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * Global constant values
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Globals
+{
+
+ /** MCMP protocol prefix */
+ public static final String MCMP = "MCMP/";
+
+ /** MCMP protocol Unknown-Type warning message prefix */
+ public static final String UNKNOWN_TYPE = "Unknown-Type:";
+
+ /** MCMP protocol Unknown-Resource warning message prefix */
+ public static final String UNKNOWN_RESOURCE = "Unknown-Resource:";
+
+ /** MCMP protocol error message prefix */
+ public static final String ERROR = "Error:";
+
+ /** MCMP protocol Resource Header name */
+ public static final String SERVER_RESOURCE = "X-Server-Resource";
+
+ /** MCMP protocol Command Header name */
+ public static final String SERVER_COMMAND = "X-Server-Command";
+
+ /** MCMP protocol Server Ping name */
+ public static final String SERVER_PING = "X-Server-Ping";
+
+ /** RFC 822 textual Date format used by SimpleDateFormat */
+ public static final String RFC_822_FMT = "EEE, d MMM yyyy HH:mm:ss
Z";
+
+ private Globals()
+ {
+ // Disable creation
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Globals.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Host.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Host.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Host.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,126 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Host resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Host extends Resource
+{
+
+ public Parameter Balancer = addParameter("Balancer",
false, ParameterType.Resource);
+
+ public Parameter ServerName = addParameter("ServerName",
false, ParameterType.String);
+ public Parameter ServerAlias = addParameter("ServerAlias",
false, ParameterType.StringArray);
+ public Parameter DocumentRoot = addParameter("DocumentRoot",
false, ParameterType.String);
+ public Parameter IsVirtual = addParameter("IsVirtual",
false, ParameterType.Boolean);
+ public Parameter KeepAlive = addParameter("KeepAlive",
false, ParameterType.Boolean);
+ public Parameter KeepAliveTimeout =
addParameter("KeepAliveTimeout", false, ParameterType.Long);
+ public Parameter MaxKeepAliveRequests =
addParameter("MaxKeepAliveRequests", false, ParameterType.Integer);
+ public Parameter TimeOut = addParameter("TimeOut",
false, ParameterType.Long);
+ public Parameter LimitRequestBody =
addParameter("LimitRequestBody", false, ParameterType.Integer);
+ public Parameter Address = addParameter("Address",
false, ParameterType.String);
+ public Parameter Port = addParameter("Port",
false, ParameterType.Integer);
+ public Parameter Status = addParameter("Status",
false, ParameterType.State);
+
+ public ResourceType getResourceType() { return ResourceType.Server; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+
+ private String resourceName;
+ private HashMap<String, Application> applicationMap;
+
+ public Collection<Application> getApplications()
+ {
+ return applicationMap.values();
+ }
+
+ public Application getApplication(String name)
+ {
+ return applicationMap.get(name);
+ }
+
+ public void addApplication(Application application)
+ {
+ applicationMap.put(application.getResourceName(), application);
+ }
+
+ public void removeApplication(Application application)
+ {
+ applicationMap.remove(application);
+ }
+
+ private Host()
+ {
+ // Disable creation of unlinked resource
+ }
+
+ protected Host(ManagedServer managedServer, Balancer balancer, String name)
+ {
+ super(managedServer);
+ resourceName = name;
+ applicationMap = new HashMap<String, Application>();
+ if (balancer != null) {
+ // Reference this Host to the Balancer
+ balancer.addHost(this);
+ try {
+ Balancer.setValue(balancer);
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+ }
+
+ protected Host(ManagedServer managedServer, String name)
+ {
+ this(managedServer, (Balancer)managedServer.getResource(ResourceType.Balancer),
name);
+ }
+
+ protected Host(ManagedServer managedServer)
+ {
+ this(managedServer, Default.NAME);
+ }
+
+ public void onUpdateResource(Parameter p, Resource ov, Resource nv)
+ {
+ if (nv.getResourceType() == ResourceType.Balancer) {
+ // Changing Balancer for this host
+ Balancer ob = (Balancer)ov;
+ Balancer nb = (Balancer)nv;
+ if (ob != null)
+ ob.removeHost(this);
+ if (nb != null)
+ nb.addHost(this);
+ }
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Host.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/HttpMessage.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/HttpMessage.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/HttpMessage.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,163 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.io.InputStream;
+
+import java.net.URL;
+import java.net.URLEncoder;
+import java.net.HttpURLConnection;
+
+import java.net.ProtocolException;
+import java.net.MalformedURLException;
+
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Represents the HTTP protocol Message to remote Web Server
+ * instance using MCMP protocol
+ *
+ * @author Mladen Turk
+ *
+ */
+public class HttpMessage extends Message
+{
+
+ private static final String GET = "GET";
+ private static final String OK = "OK";
+ private static final String ERR_500 = "?Error: 502; Internal Server
Error";
+ private static final String ERR_502 = "?Error: 502; Bad Gateway";
+ private static final String ERR_505 = "?Error: 505; HTTP Version not
supported";
+ private static final String ERR_400 = "?Error: 400; Bad Request";
+ private static final String ERR_403 = "?Error: 403; Forbidded";
+ private static final String ERR_404 = "?Error: 404; Not Found";
+ private static final String ERR_405 = "?Error: 405; Method Not
Allowed";
+ private int responseCode = 0;
+ private String responseDesc = "";
+
+ /**
+ * Creates an empty Message
+ */
+ public HttpMessage()
+ {
+ }
+
+ protected Message getInstance()
+ {
+ return this;
+ }
+
+ /**
+ * Return HTTP response code
+ */
+ public int getResponseCode()
+ {
+ return responseCode;
+ }
+
+ public String getResponse(String query)
+ {
+ HttpURLConnection conn;
+ try {
+ URL url = new URL(getMessageUrl());
+ conn = (HttpURLConnection)url.openConnection();
+ conn.setRequestMethod(GET);
+ } catch (MalformedURLException u) {
+ responseCode = HttpURLConnection.HTTP_BAD_REQUEST;
+ return ERR_400;
+ } catch (ProtocolException e) {
+ responseCode = HttpURLConnection.HTTP_BAD_METHOD;
+ return ERR_405;
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_FORBIDDEN;
+ return ERR_403;
+ }
+ conn.setAllowUserInteraction(false);
+ conn.setUseCaches(false);
+ conn.setDoInput(true);
+ conn.setDoOutput(false);
+ conn.setRequestProperty(Globals.SERVER_RESOURCE, query);
+ if (authorization != null) {
+ // Add Authorization header
+ conn.setRequestProperty("Authorization", authorization);
+ }
+
+ try {
+ conn.setConnectTimeout(connectTimeout);
+ conn.setReadTimeout(readTimeout);
+ conn.connect();
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_BAD_GATEWAY;
+ return ERR_502;
+ }
+ try {
+ responseCode = conn.getResponseCode();
+ responseDesc = conn.getResponseMessage();
+ } catch (IOException x) {
+ responseCode = HttpURLConnection.HTTP_VERSION;
+ conn.disconnect();
+ return ERR_505;
+ }
+
+ if (responseCode != HttpURLConnection.HTTP_OK) {
+ StringBuffer eb = new StringBuffer("?Error: ");
+ eb.append(responseCode);
+ eb.append("; ");
+ eb.append(responseDesc);
+ return eb.toString();
+ }
+
+ InputStream is;
+ try {
+ is = conn.getInputStream();
+ } catch (IOException e) {
+ responseCode = HttpURLConnection.HTTP_INTERNAL_ERROR;
+ conn.disconnect();
+ return ERR_500;
+ }
+ StringBuffer s = new StringBuffer();
+ int rd;
+ byte [] bb = new byte[1024];
+ try {
+ while ((rd = is.read(bb)) > 0) {
+ s.append(new String(bb, 0, rd, Default.CHARSET));
+ if (rd < 1024)
+ break;
+ }
+ } catch (Exception e) {
+ // Ignore. Return what we've got so far.
+ }
+ String r = s.toString();
+ if (s.length() == 0)
+ return OK;
+ else
+ return r;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/HttpMessage.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/InvalidValueException.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/InvalidValueException.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/InvalidValueException.java 2008-05-28 15:47:01 UTC
(rev 1630)
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/** InvalidValueException
+ *
+ * @author Mladen Turk
+ *
+ */
+public class InvalidValueException extends Exception {
+
+ public InvalidValueException()
+ {
+ super();
+ }
+
+ public InvalidValueException(String msg)
+ {
+ super(msg);
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/InvalidValueException.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ManagedServer.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ManagedServer.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ManagedServer.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,146 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.LinkedList;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Represents the remote Web Server instance
+ *
+ * @author Mladen Turk
+ *
+ */
+public class ManagedServer
+{
+
+ private boolean initialized = false;
+ private Manager systemManager;
+ private Server systemServer;
+ private Host defaultHost;
+ private Balancer defaultBalancer;
+ private ApplicationPool defaultAppPool;
+
+ private HashMap<String, Host> hostMap;
+ private HashMap<String, Balancer> balancerMap;
+ private HashMap<String, ApplicationPool> appPoolMap;
+
+ /**
+ * Creates the empty instance of the ManagedServer
+ */
+ public ManagedServer()
+ {
+ hostMap = new HashMap<String, Host>();
+ balancerMap = new HashMap<String, Balancer>();
+ appPoolMap = new HashMap<String, ApplicationPool>();
+
+ // Default Resource objects
+ systemManager = new Manager(this);
+ systemServer = new Server(this);
+ defaultHost = new Host(this);
+ defaultBalancer = new Balancer(this);
+ defaultAppPool = new ApplicationPool(this);
+
+ hostMap.put(Default.NAME, defaultHost);
+ balancerMap.put(Default.NAME, defaultBalancer);
+ appPoolMap.put(Default.NAME, defaultAppPool);
+
+ }
+
+ public Collection<Host> getHosts()
+ {
+ return hostMap.values();
+ }
+
+ public Collection<Balancer> getBalancers()
+ {
+ return balancerMap.values();
+ }
+
+ public Collection<ApplicationPool> getApplicationPools()
+ {
+ return appPoolMap.values();
+ }
+
+ /**
+ * Gets the Resource object
+ * @param type ResourceType to get
+ */
+ public Resource getResource(ResourceType type)
+ {
+ if (type == ResourceType.Manager)
+ return systemManager;
+ else if (type == ResourceType.Server)
+ return systemServer;
+ else if (type == ResourceType.Host)
+ return defaultHost;
+ else if (type == ResourceType.Balancer)
+ return defaultBalancer;
+ else if (type == ResourceType.ApplicationPool)
+ return defaultAppPool;
+ else
+ return new GenericResource(this);
+ }
+
+ /**
+ * Gets the Resource object
+ * @param name Name of the Resource object to get
+ * @param type ResourceType to get
+ */
+ public Resource getResource(String name, ResourceType type)
+ {
+ if (name == null || name.equalsIgnoreCase(Default.NAME))
+ return getResource(type);
+ else if (type == ResourceType.Host) {
+ Host host = hostMap.get(name);
+ if (host == null) {
+ host = new Host(this, name);
+ hostMap.put(name, host);
+ }
+ return host;
+ }
+ else if (type == ResourceType.Balancer) {
+ Balancer balancer = balancerMap.get(name);
+ if (balancer == null) {
+ balancer = new Balancer(this, name);
+ balancerMap.put(name, balancer);
+ }
+ return balancer;
+ }
+ else if (type == ResourceType.ApplicationPool) {
+ ApplicationPool appPool = appPoolMap.get(name);
+ if (appPool == null) {
+ appPool = new ApplicationPool(this, name);
+ appPoolMap.put(name, appPool);
+ }
+ return appPool;
+ }
+ else
+ return new GenericResource(this, name);
+ }
+
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ManagedServer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Manager.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Manager.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Manager.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,67 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Manager resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Manager extends Resource
+{
+ public Parameter ProtocolVersion =
addParameter("ProtocolVersion", true, ParameterType.String);
+ public Parameter ServerId = addParameter("ServerId",
true, ParameterType.String);
+ public Parameter Advertise = addParameter("Advertise",
true, ParameterType.Boolean);
+ public Parameter AdvertiseMode = addParameter("AdvertiseMode",
true, ParameterType.AdvertiseMode);
+ public Parameter Status = addParameter("Status",
true, ParameterType.Integer);
+ public Parameter Strict = addParameter("Strict",
false, ParameterType.Boolean);
+ public Parameter CaseInsensitive =
addParameter("CaseInsensitive", false, ParameterType.Boolean);
+ public Parameter SecurityKey = addParameter("SecurityKey",
false, ParameterType.String);
+
+
+ public ResourceType getResourceType() { return ResourceType.Manager; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+
+ private String resourceName = "Manager";
+
+ private Manager()
+ {
+ // Disable creation of unlinked resource
+ }
+
+ protected Manager(ManagedServer managedServer)
+ {
+ super(managedServer, Default.MANAGER_ID);
+ }
+}
+
+
+
Property changes on: sandbox/aloha/java/org/jboss/aloha/Manager.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Member.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Member.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Member.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,126 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Member resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Member extends Resource
+{
+ public Parameter Balancer = addParameter("Balancer",
true, ParameterType.Resource);
+
+ public Parameter Type = addParameter("Type",
false, ParameterType.ProtocolType);
+ public Parameter Address = addParameter("Address",
false, ParameterType.String);
+ public Parameter Port = addParameter("Port",
false, ParameterType.Integer);
+ public Parameter Route = addParameter("Route",
false, ParameterType.String);
+ public Parameter Ping = addParameter("Ping",
false, ParameterType.Integer);
+ public Parameter MaxConnections =
addParameter("MaxConnections", false, ParameterType.Integer);
+ public Parameter MinConnections =
addParameter("MinConnections", false, ParameterType.Integer);
+ public Parameter MaxClients = addParameter("MaxClients",
false, ParameterType.Integer);
+ public Parameter TTL = addParameter("TTL",
false, ParameterType.Integer);
+ public Parameter LF = addParameter("LF",
false, ParameterType.Integer);
+ public Parameter Distance = addParameter("Distance",
false, ParameterType.Integer);
+ public Parameter Activation = addParameter("Activation",
false, ParameterType.State);
+ public Parameter FlushMode = addParameter("FlushMode",
false, ParameterType.Char);
+ public Parameter FlushTimeout = addParameter("FlushTimeout",
false, ParameterType.Long);
+ // Statistical Data
+ public Parameter State = addParameter("State",
true, ParameterType.State);
+ public Parameter Error = addParameter("Error",
true, ParameterType.String);
+ public Parameter Busy = addParameter("Busy",
true, ParameterType.Integer);
+ public Parameter Connected = addParameter("Connected",
true, ParameterType.Integer);
+ public Parameter Elected = addParameter("Elected",
true, ParameterType.Integer);
+ public Parameter StickySessions =
addParameter("StickySessions", true, ParameterType.Integer);
+ public Parameter ClientErrors = addParameter("ClientErrors",
true, ParameterType.Integer);
+ public Parameter NodeErrors = addParameter("NodeErrors",
true, ParameterType.Integer);
+ public Parameter Trace = addParameter("Trace",
true, ParameterType.Integer);
+ public Parameter TraceErrors = addParameter("TraceErrors",
true, ParameterType.Integer);
+ public Parameter Readed = addParameter("Readed",
true, ParameterType.Long);
+ public Parameter Transferred = addParameter("Transferred",
true, ParameterType.Long);
+
+
+ public ResourceType getResourceType() { return ResourceType.Member; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return Balancer.getResource(); }
+
+ private String resourceName;
+ private HashMap<String, MemberApplication> applicationMap;
+
+ private Member()
+ {
+ // Disable creation of unnamed resource
+ }
+
+ protected Member(Balancer balancer, String name)
+ {
+ resourceName = name;
+ applicationMap = new HashMap<String, MemberApplication>();
+ if (balancer != null) {
+ // Reference this Member to the Balancer
+ balancer.addMember(this);
+ try {
+ Balancer.setValue(balancer);
+ } catch (Exception e) {
+ // Ignore
+ }
+ try {
+ for (Host h : balancer.getHosts()) {
+ for (Application a : h.getApplications()) {
+ /* Add existing Applications */
+ addApplication(a);
+ }
+ }
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+
+ }
+
+ protected Member(ManagedServer managedServer, String name)
+ {
+ this((Balancer)managedServer.getResource(ResourceType.Balancer), name);
+ }
+
+ public Collection<MemberApplication> getApplications()
+ {
+ return applicationMap.values();
+ }
+
+ public void addApplication(Application application)
+ {
+ MemberApplication ma = new MemberApplication(this, application);
+ applicationMap.put(application.getResourceName(), ma);
+ }
+}
+
+
+
Property changes on: sandbox/aloha/java/org/jboss/aloha/Member.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/MemberApplication.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/MemberApplication.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/MemberApplication.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,71 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * MemberApplication resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class MemberApplication extends Resource
+{
+
+ public Parameter Member = addParameter("Member",
true, ParameterType.Resource);
+ public Parameter Application = addParameter("Application",
true, ParameterType.Resource);
+
+ public Parameter State = addParameter("State",
false, ParameterType.State);
+ // Statistical Data
+ public Parameter Busy = addParameter("Busy",
true, ParameterType.Integer);
+ public Parameter Transactions = addParameter("Transactions",
true, ParameterType.Integer);
+ public Parameter ClientErrors = addParameter("ClientErrors",
true, ParameterType.Integer);
+ public Parameter NodeErrors = addParameter("NodeErrors",
true, ParameterType.Integer);
+ public Parameter Readed = addParameter("Readed",
true, ParameterType.Long);
+ public Parameter Transferred = addParameter("Transferred",
true, ParameterType.Long);
+
+ public ResourceType getResourceType() { return ResourceType.Application; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return member; }
+
+ private String resourceName;
+ private Member member;
+ private Application application;
+
+ private MemberApplication()
+ {
+ // Disable creation of unnamed resource
+ }
+
+ public MemberApplication(Member member, Application application)
+ {
+ this.member = member;
+ this.application = application;
+ resourceName = application.getResourceName();
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/MemberApplication.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Message.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Message.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Message.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,125 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import org.jboss.aloha.util.*;
+
+/**
+ * Represents the Message send to remote Web Server instance
+ * using MCMP protocol
+ *
+ * @author Mladen Turk
+ *
+ */
+public abstract class Message
+{
+
+ private MessageProtocol protocol = MessageProtocol.Http;
+ private Command cmd = Command.Info;
+
+ private String host = "localhost";
+ private int port = 0;
+ private String url = Default.MANAGER_URL;
+ protected int connectTimeout = Default.CONNECT_TIMEOUT;
+ protected int readTimeout = Default.READ_TIMEOUT;
+ protected String authorization = null;
+
+ /**
+ * Creates an empty connection to ManagedServer
+ */
+ public Message()
+ {
+ }
+
+ protected abstract int getResponseCode();
+ protected abstract String getResponse(String query);
+ protected abstract Message getInstance();
+
+ public void setProtocol(MessageProtocol v) { protocol = v; }
+
+ public void setProtocol(String v)
+ throws IllegalArgumentException
+ {
+ protocol = MessageProtocol.valueOfIgnoreCase(v);
+ }
+
+ public MessageProtocol getProtocol() { return protocol; }
+
+
+ public void setCommand(Command v) { cmd = v; }
+ public Command getCommand() { return cmd; }
+
+ public void setHost(String v) { host = v; }
+ public String getHost() { return host; }
+
+ public void setPort(int v) { port = v; }
+ public int getPort() { return port; }
+
+ public void setManagerUrl(String v) { url = v; }
+ public String getManagerUrl() { return url; }
+
+ public void setConnectTimeout(int v) { connectTimeout = v; }
+ public int getConnectTimeout() { return connectTimeout; }
+
+ public void setReadTimeout(int v) { readTimeout = v; }
+ public int getReadTimeout() { return readTimeout; }
+
+ public String getAuthorization() { return authorization; }
+
+ /**
+ * Sets the Basic Authorization credentials
+ */
+ public void setAuthorization(String username, String password)
+ {
+ if (username != null && password != null)
+ authorization = "Basic " + Base64.encode(username + ":" +
password);
+ }
+
+ /**
+ * Sets the Authorization credentials
+ */
+ public void setAuthorization(String authorization)
+ {
+ this.authorization = authorization;
+ }
+
+ public String getMessageUrl()
+ {
+ StringBuffer sb = new StringBuffer(protocol.name().toLowerCase());
+ sb.append("://");
+ sb.append(host);
+ if (port > 0) {
+ sb.append(':');
+ sb.append(port);
+ }
+ sb.append(url);
+ sb.append('/');
+ sb.append(cmd.name());
+ return sb.toString();
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Message.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/MessageFactory.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/MessageFactory.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/MessageFactory.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,118 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import org.jboss.aloha.util.*;
+
+/**
+ * MessageFactory
+ *
+ * @author Mladen Turk
+ *
+ */
+public class MessageFactory
+{
+
+ private MessageProtocol protocol = MessageProtocol.Http;
+ private ResponseBodyParser parser = new ResponseBodyParser();
+ private Message message;
+ private String host = "localhost";
+ private int port = 0;
+ private String url = Default.MANAGER_URL;
+ protected int connectTimeout = Default.CONNECT_TIMEOUT;
+ protected int readTimeout = Default.READ_TIMEOUT;
+ protected String authorization = null;
+
+ /**
+ * Creates an empty connection to ManagedServer
+ */
+ public MessageFactory(Message message)
+ {
+ this.message = message;
+ }
+
+ public void setProtocol(MessageProtocol v) { protocol = v; }
+
+ public void setProtocol(String v)
+ throws IllegalArgumentException
+ {
+ protocol = MessageProtocol.valueOfIgnoreCase(v);
+ }
+
+ public MessageProtocol getProtocol() { return protocol; }
+
+
+ public void setHost(String v) { host = v; }
+ public String getHost() { return host; }
+
+ public void setPort(int v) { port = v; }
+ public int getPort() { return port; }
+
+ public void setManagerUrl(String v) { url = v; }
+ public String getManagerUrl() { return url; }
+
+ public void setConnectTimeout(int v) { connectTimeout = v; }
+ public int getConnectTimeout() { return connectTimeout; }
+
+ public void setReadTimeout(int v) { readTimeout = v; }
+ public int getReadTimeout() { return readTimeout; }
+
+ public String getAuthorization() { return authorization; }
+
+ /**
+ * Sets the Basic Authorization credentials
+ */
+ public void setAuthorization(String username, String password)
+ {
+ if (username != null && password != null)
+ authorization = "Basic " + Base64.encode(username + ":" +
password);
+ }
+
+ /**
+ * Sets the Authorization credentials
+ */
+ public void setAuthorization(String authorization)
+ {
+ this.authorization = authorization;
+ }
+
+ public Message getMessage()
+ {
+ Message msg = message.getInstance();
+
+ msg.setProtocol(protocol);
+ msg.setHost(host);
+ msg.setPort(port);
+ msg.setManagerUrl(url);
+ msg.setConnectTimeout(connectTimeout);
+ msg.setReadTimeout(readTimeout);
+ msg.setAuthorization(authorization);
+
+ return msg;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/MessageFactory.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/MessageProtocol.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/MessageProtocol.java (rev
0)
+++ sandbox/aloha/java/org/jboss/aloha/MessageProtocol.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,46 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * MessageProtocol enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum MessageProtocol
+{
+ Http,
+ Https;
+
+ public static MessageProtocol valueOfIgnoreCase(String name)
+ {
+ for (MessageProtocol e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ throw new IllegalArgumentException("Invalid initializer: " + name);
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/MessageProtocol.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Parameter.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Parameter.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Parameter.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,468 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.Locale;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+/**
+ * Parameter object
+ *
+ * @author Mladen Turk
+ *
+ */
+public class Parameter
+{
+
+ private SimpleDateFormat df = new SimpleDateFormat(Globals.RFC_822_FMT, Locale.US);
+ private boolean readOnly = false;
+ private boolean modified = false;
+ private boolean updated = false;
+ private boolean initset = false;
+ private String name;
+ private Resource holder = null;
+ private String vS = "";
+ private String [] sA = { ""};
+ private int [] iA = { 0 };
+ private Date vD = new Date(0);
+ private int vI = 0;
+ private char vC = '\0';
+ private long vL = 0L;
+ private BooleanType bT = BooleanType.False;
+ private AdvertiseMode aM = AdvertiseMode.Off;
+ private BalancerMethod bM = BalancerMethod.Unknown;
+ private StateMode sM = StateMode.Unknown;
+ private Resource vR = null;
+ private ProtocolType pT = ProtocolType.Ajp;
+ private ParameterType type;
+
+ private Parameter()
+ {
+ // Disable creation
+ }
+
+ public Parameter(Resource holder, String name, boolean readOnly, ParameterType type)
+ {
+ this.holder = holder;
+ this.name = name;
+ this.readOnly = readOnly;
+ this.type = type;
+ }
+
+ public Parameter(String name, boolean readOnly, ParameterType type)
+ {
+ this(null, name, readOnly, type);
+ }
+
+ public Parameter(String name, boolean readOnly, ParameterType type,
+ String defaultValue)
+ {
+ this(name, readOnly, type);
+ putValue(defaultValue);
+ }
+
+ public Parameter(String name, String value)
+ {
+ this(name, false, ParameterType.String, value);
+ initset = true;
+ }
+
+ public boolean isReadOnly()
+ {
+ return readOnly;
+ }
+
+ protected boolean isModified()
+ {
+ return modified;
+ }
+
+ protected boolean isUpdated()
+ {
+ return updated;
+ }
+
+ protected void clearModifiedFlag()
+ {
+ modified = false;
+ }
+
+ protected void clearUpdatedFlag()
+ {
+ updated = false;
+ }
+
+ protected boolean equals(String name)
+ {
+ return this.name.equalsIgnoreCase(name);
+ }
+
+ protected boolean equals(Parameter other)
+ {
+ return this.name.equalsIgnoreCase(other.name);
+ }
+
+ private void canModify()
+ throws IllegalAccessException
+ {
+ if (!initset) {
+ initset = true;
+ return;
+ }
+ if (readOnly) {
+ throw new IllegalAccessException("Cannot update: " + name);
+ }
+ else {
+ modified = true;
+ }
+ }
+
+ public void setValue(Parameter value)
+ throws IllegalAccessException
+ {
+ canModify();
+ putValue(value.getValue());
+ }
+
+ public void setValue(int value)
+ throws IllegalAccessException
+ {
+ canModify();
+ vI = value;
+ }
+
+ public void setValue(char value)
+ throws IllegalAccessException
+ {
+ canModify();
+ vC = Character.toUpperCase(value);
+ }
+
+ public void setValue(boolean value)
+ throws IllegalAccessException
+ {
+ canModify();
+ if (value)
+ bT = BooleanType.True;
+ else
+ bT = BooleanType.False;
+ }
+
+ public void setValue(long value)
+ throws IllegalAccessException
+ {
+ canModify();
+ vL = value;
+ if (type == ParameterType.Date ||
+ type == ParameterType.Rfc822Date)
+ vD = new Date(value);
+ }
+
+ public void setValue(Date value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null) {
+ vD = value;
+ vL = value.getTime();
+ }
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(AdvertiseMode value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ aM = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(BalancerMethod value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ bM = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(ProtocolType value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ pT = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(StateMode value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ sM = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(BooleanType value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ bT = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(Resource value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null && value != vR) {
+ if (holder != null) {
+ holder.onUpdateResource(this, vR, value);
+ }
+ vR = value;
+ }
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(String value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null) {
+ vS = value;
+ if (type == ParameterType.StringArray)
+ sA = value.split("\\s+");
+ }
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void setValue(String [] value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ sA = value;
+ else
+ throw new InvalidValueException(name);
+ }
+ public void setValue(int [] value)
+ throws IllegalAccessException, InvalidValueException
+ {
+ canModify();
+ if (value != null)
+ iA = value;
+ else
+ throw new InvalidValueException(name);
+ }
+
+ public void putValue(Parameter value)
+ {
+ putValue(value.getValue());
+ }
+
+ public void putValue(String value)
+ {
+ try {
+ if (value == null || value.length() == 0) {
+ // Ignore
+ return;
+ }
+ else if (type == ParameterType.String) {
+ vS = value;
+ }
+ else if (type == ParameterType.StringArray) {
+ vS = value;
+ sA = value.split("\\s+");
+ }
+ else if (type == ParameterType.Char) {
+ vC = Character.toUpperCase(value.charAt(0));
+ }
+ else if (type == ParameterType.Integer) {
+ vI = Integer.parseInt(value);
+ }
+ else if (type == ParameterType.IntegerArray) {
+ vS = value;
+ sA = vS.split("\\.");
+ iA = new int[sA.length];
+ for (int i = 0; i < iA.length; i++)
+ iA[i] = Integer.parseInt(sA[i]);
+ }
+ else if (type == ParameterType.Long) {
+ vL = Long.parseLong(value);
+ }
+ else if (type == ParameterType.Date) {
+ vL = Long.parseLong(value);
+ vD = new Date(vL);
+ }
+ else if (type == ParameterType.Rfc822Date) {
+ try {
+ vD = df.parse(value);
+ } catch (ParseException e) {
+ vD = new Date(0);
+ }
+ vL = vD.getTime();
+ }
+ else if (type == ParameterType.AdvertiseMode) {
+ try {
+ aM = AdvertiseMode.valueOfIgnoreCase(value);
+ } catch (IllegalArgumentException e) {
+ // Ignore
+ }
+ }
+ else if (type == ParameterType.BalancerMethod) {
+ bM = BalancerMethod.valueOfIgnoreCase(value);
+ }
+ else if (type == ParameterType.ProtocolType) {
+ pT = ProtocolType.valueOfIgnoreCase(value);
+ }
+ else if (type == ParameterType.Boolean) {
+ bT = BooleanType.valueOfIgnoreCase(value);
+ }
+ else if (type == ParameterType.State) {
+ sM = StateMode.valueOfIgnoreCase(value);
+ }
+ updated = true;
+ } catch (Exception e) {
+ // Ignore
+ }
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public String getValue()
+ {
+ StringBuffer sb = new StringBuffer("");
+ if (type == ParameterType.String) {
+ sb.append(vS);
+ }
+ else if (type == ParameterType.StringArray) {
+ sb.append(sA[0]);
+ for (int i = 1; i < sA.length; i++) {
+ sb.append(' ');
+ sb.append(sA[i]);
+ }
+ }
+ else if (type == ParameterType.Integer) {
+ sb.append(vI);
+ }
+ else if (type == ParameterType.IntegerArray) {
+ sb.append(iA[0]);
+ for (int i = 1; i < iA.length; i++) {
+ sb.append('.');
+ sb.append(iA[i]);
+ }
+ }
+ else if (type == ParameterType.Char) {
+ sb.append(vC);
+ }
+ else if (type == ParameterType.Long) {
+ sb.append(vL);
+ }
+ else if (type == ParameterType.Date) {
+ sb.append(vL);
+ }
+ else if (type == ParameterType.Rfc822Date) {
+ sb.append(df.format(vD));
+ }
+ else if (type == ParameterType.AdvertiseMode) {
+ sb.append(aM);
+ }
+ else if (type == ParameterType.BalancerMethod) {
+ sb.append(bM);
+ }
+ else if (type == ParameterType.ProtocolType) {
+ sb.append(pT);
+ }
+ else if (type == ParameterType.Boolean) {
+ sb.append(bT);
+ }
+ else if (type == ParameterType.Resource) {
+ sb.append(vR.getResourceName());
+ }
+ else if (type == ParameterType.State) {
+ sb.append(sM.valueOf());
+ }
+ return sb.toString();
+ }
+
+ public String getString() { return vS; }
+ public String [] getStringArray() { return sA; }
+ public char getChar() { return vC; }
+ public int getInteger() { return vI; }
+ public int [] getIntegerArray() { return iA; }
+ public long getLong() { return vL; }
+ public Date getDate() { return vD; }
+ public AdvertiseMode getAdvertiseMode() { return aM; }
+ public BalancerMethod getBalancerMethod() { return bM; }
+ public BooleanType getBooleanType() { return bT; }
+ public ProtocolType getProtocolType() { return pT; }
+ public boolean getBoolean() { return bT.valueOf(); }
+ public StateMode getStateMode() { return sM; }
+ public Resource getResource() { return vR; }
+
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer(name);
+ sb.append('=');
+ String v = getValue();
+ if ((v.indexOf(' ') >= 0) || (v.indexOf(';') >= 0)) {
+ sb.append('"');
+ sb.append(v);
+ sb.append('"');
+ }
+ else
+ sb.append(v);
+ return sb.toString();
+ }
+
+ public String toAttribute()
+ {
+ StringBuffer sb = new StringBuffer(name);
+ sb.append("=\"");
+ sb.append(getValue());
+ sb.append('"');
+ return sb.toString();
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Parameter.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ParameterType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ParameterType.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ParameterType.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,49 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * Resource parameter types
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum ParameterType
+{
+ String,
+ StringArray,
+ Integer,
+ IntegerArray,
+ Char,
+ Boolean,
+ State,
+ Long,
+ Date,
+ Rfc822Date,
+ BalancerMethod,
+ Resource,
+ ProtocolType,
+ AdvertiseMode;
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ParameterType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ParameterUpdateCallback.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ParameterUpdateCallback.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ParameterUpdateCallback.java 2008-05-28 15:47:01
UTC (rev 1630)
@@ -0,0 +1,38 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * ParameterUpdate callback interface
+ *
+ * @author Mladen Turk
+ *
+ */
+public interface ParameterUpdateCallback
+{
+
+ public void onUpdateResource(Parameter p, Resource ov, Resource nv);
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ParameterUpdateCallback.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ProtocolType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ProtocolType.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ProtocolType.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,47 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * ProtocolType enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum ProtocolType
+{
+ Ajp,
+ Http,
+ Https;
+
+ public static ProtocolType valueOfIgnoreCase(String name)
+ {
+ for (ProtocolType e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ throw new IllegalArgumentException("Invalid initializer: " + name);
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ProtocolType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Resource.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Resource.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Resource.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,197 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.LinkedList;
+import org.jboss.aloha.util.*;
+
+/**
+ * Core Resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public abstract class Resource implements ParameterUpdateCallback
+{
+ private long id;
+ private ManagedServer managedServer;
+ private LinkedList<Parameter> parameterList = new
LinkedList<Parameter>();
+
+ protected Parameter addParameter(String name, boolean readOnly, ParameterType type)
+ {
+ Parameter p = new Parameter(this, name, readOnly, type);
+ parameterList.add(p);
+ return p;
+ }
+
+ protected void addParameter(Parameter p)
+ {
+ parameterList.add(p);
+ }
+
+ /**
+ * Creates system Resource with designated Id
+ */
+ protected Resource(ManagedServer managedServer, long id)
+ {
+ this.id = id;
+ this.managedServer = managedServer;
+ }
+
+ protected Resource(ManagedServer managedServer)
+ {
+ this(managedServer, Utils.Id());
+ }
+
+ protected Resource()
+ {
+ this(null, Utils.Id());
+ }
+
+ public abstract ResourceType getResourceType();
+ public abstract String getResourceName();
+ public abstract Resource getResourceParent();
+
+ public ManagedServer getManagedServer() { return managedServer; }
+
+ public void onUpdateResource(Parameter p, Resource ov, Resource nv)
+ {
+ // Implemented in derived classes
+ }
+
+ /**
+ * Get the unique Id for this Resource generated at creation time
+ */
+ public long Id() { return id; }
+
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer(getClass().getSimpleName());
+ sb.append(" ResourceType=\"");
+ sb.append(getResourceType());
+ sb.append('"');
+ sb.append(" ResourceId=\"");
+ sb.append(Utils.hex(id));
+ sb.append('"');
+ sb.append(" ResourceName=\"");
+ sb.append(getResourceName());
+ sb.append('"');
+ for (Parameter p : parameterList) {
+ sb.append(' ');
+ sb.append(p.toAttribute());
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Returns True if any of the updateable parameters
+ * has been modified
+ */
+ public boolean isModified()
+ {
+ for (Parameter p : parameterList) {
+ if (!p.isReadOnly() &&
+ p.isModified()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns True if any of the parameters
+ * has been updated
+ */
+ public boolean isUpdated()
+ {
+ for (Parameter p : parameterList) {
+ if (p.isUpdated()) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Clear modification flags for all Parameters
+ * This method should be invoked after the WebServer
+ * has been updated
+ */
+ public void clearModifiedFlag()
+ {
+ for (Parameter p : parameterList) {
+ p.clearModifiedFlag();
+ }
+ }
+
+ /**
+ * Clear update flags for all Parameters
+ * This method should be invoked after the Resource
+ * is used
+ */
+ public void clearUpdatedFlag()
+ {
+ for (Parameter p : parameterList) {
+ p.clearUpdatedFlag();
+ }
+ }
+
+ public String getUpdateString()
+ {
+ StringBuffer sb = new StringBuffer(getResourceName());
+ for (Parameter p : parameterList) {
+ if (!p.isReadOnly() &&
+ p.isModified()) {
+ sb.append("; ");
+ sb.append(p);
+ }
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Sets the name=value pair<br/>
+ * This method shuld be invoked from the Parser to update the
+ * parameters received from the mod_manager.
+ * @param name Parameter name
+ * @param value Parameter value. The parameter value will be converted
+ * from String to the corresponding native type.
+ */
+ public void putValue(String name, String value)
+ {
+ for (Parameter p : parameterList) {
+ if (p.equals(name)) {
+ p.putValue(value);
+ break;
+ }
+ }
+ }
+
+ public LinkedList<Parameter> getParameters()
+ {
+ return parameterList;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Resource.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ResourceType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ResourceType.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ResourceType.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,53 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * ResourceType enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum ResourceType
+{
+ Unknown,
+ Manager,
+ Server,
+ ApplicationPool,
+ Balancer,
+ Member,
+ Host,
+ Application;
+
+ public static ResourceType valueOfIgnoreCase(String name)
+ {
+ for (ResourceType e : values()) {
+ if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ return ResourceType.Unknown;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ResourceType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java 2008-05-28 15:47:01 UTC
(rev 1630)
@@ -0,0 +1,269 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Date;
+import java.util.Locale;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+
+import java.util.LinkedList;
+
+/**
+ * Parse the body of the response HTTP MCMP message.
+ * The message body is text/plain with ISO_8895_1 character set.
+ *
+ * @author Mladen Turk
+ *
+ */
+public class ResponseBodyParser
+{
+ private static int EIO = 5;
+ private static int EINVAL = 22;
+ private static String CRLF = "\r\n";
+
+ private int errorCode = 0;
+ private String errorDescription = "No error";
+ private LinkedList<String> bodyLines = new LinkedList<String>();
+ private ResponseType responseType = ResponseType.Unparsed;
+
+ private LinkedList<GenericResource> grL = new
LinkedList<GenericResource>();
+
+
+ private void splitLines(String body)
+ {
+ if (body == null || body.length() < 1)
+ return;
+ String [] lines = body.split(CRLF);
+ for (int i = 0; i < lines.length; i++) {
+ String line = lines[i].trim();
+ if (line.length() > 0) {
+ bodyLines.add(line);
+ }
+ }
+ }
+
+ public void clear()
+ {
+ errorCode = 0;
+ errorDescription = "No error";
+ responseType = ResponseType.Empty;
+ bodyLines.clear();
+ grL.clear();
+ }
+
+ public void parse(String body)
+ {
+ clear();
+ splitLines(body);
+ if (bodyLines.size() > 0) {
+ parseFirstLine();
+ if (responseType == ResponseType.Ok) {
+ for (int i = 1; i < bodyLines.size(); i ++) {
+ parseLine(bodyLines.get(i));
+ }
+ }
+ }
+ }
+
+ public ResponseBodyParser()
+ {
+ }
+
+ public ResponseBodyParser(String body)
+ {
+ parse(body);
+ }
+
+ public ResponseBodyParser(byte[] body)
+ {
+ try {
+ String bstr = new String(body, Default.CHARSET);
+ bodyLines = new LinkedList<String>();
+ parse(bstr);
+ } catch (UnsupportedEncodingException e) {
+ // Ignore
+ }
+ }
+
+ public ResponseType getResponseType() { return responseType; }
+ public int getErrorCode() { return errorCode; }
+ public String getErrorDescription() { return errorDescription; }
+
+ public int numLines()
+ {
+ return bodyLines.size();
+ }
+
+ private void parseFirstLine()
+ {
+ try {
+ String line = bodyLines.getFirst();
+ if (line.charAt(0) == '?') {
+ if (line.startsWith(Globals.ERROR, 1)) {
+ responseType = ResponseType.Error;
+ String ep = line.substring(Globals.ERROR.length() + 1).trim();
+ String [] ee = ep.split(";\\s*");
+ if (ee.length == 2) {
+ ee[1] = ee[1].trim();
+ try {
+ errorCode = Integer.parseInt(ee[0]);
+ errorDescription = ee[1];
+ if (errorDescription.length() == 0) {
+ errorDescription = "Unknown error " + ee[0];
+ }
+ } catch (NumberFormatException x) {
+ errorCode = EINVAL;
+ errorDescription = "Invalid errror code " + ee[0];
+ }
+ }
+ else {
+ errorCode = EINVAL;
+ if (ep.length() == 0) {
+ errorDescription = "Invalid error format";
+ }
+ else
+ errorDescription = "Unknown error " + ep;
+ }
+ }
+ else if (line.startsWith(Globals.MCMP, 1)) {
+ responseType = ResponseType.ProtocolError;
+ errorDescription = line.substring(Globals.MCMP.length() + 1).trim();
+ }
+ else if (line.startsWith(Globals.UNKNOWN_TYPE, 1)) {
+ responseType = ResponseType.UnknownType;
+ errorDescription = line.substring(Globals.UNKNOWN_TYPE.length() +
1).trim();
+ }
+ else if (line.startsWith(Globals.UNKNOWN_RESOURCE, 1)) {
+ responseType = ResponseType.UnknownResource;
+ errorDescription = line.substring(Globals.UNKNOWN_RESOURCE.length() +
1).trim();
+ }
+ else {
+ responseType = ResponseType.UnknownError;
+ errorCode = EINVAL;
+ errorDescription = line.substring(1).trim();
+ }
+ }
+ else if (line.equalsIgnoreCase("OK")) {
+ responseType = ResponseType.Ok;
+ }
+ else {
+ parseLine(line);
+ }
+ } catch (Exception e) {
+ errorCode = EIO;
+ responseType = ResponseType.UnknownError;
+ errorDescription = e.getMessage();
+ }
+ }
+
+ private void parseLine(String line)
+ {
+ if (line.charAt(0) == '?') {
+ // Ignore if not the first line
+ return;
+ }
+ else if (line.equalsIgnoreCase("OK")) {
+ // Ignore OK lines
+ return;
+ }
+ try {
+ responseType = ResponseType.Ok;
+ GenericResource gr = new GenericResource();
+ if (line.charAt(0) == '@') {
+ // First part is 'Resouce[/Name]: '
+ String [] ee = line.substring(1).split(":\\s+", 2);
+ int ps = ee[0].indexOf('/');
+ if (ps > 0) {
+ gr.setResourceType(ResourceType.valueOfIgnoreCase(ee[0].substring(0,
ps)));
+ gr.setResourceName(ee[0].substring(ps + 1));
+ }
+ else {
+ gr.setResourceType(ResourceType.valueOfIgnoreCase(ee[0]));
+ gr.setResourceName(ee[0]);
+ }
+ if (ee.length == 2)
+ line = ee[1].trim();
+ else
+ line = null;
+ }
+ if (line != null) {
+ String [] el = line.split(";\\s+");
+ for (int i = 0; i < el.length; i++) {
+ if (el[i].length() == 0) {
+ // Skip empty lines
+ continue;
+ }
+ // ParameterName=[["]ParameterValue["]]
+ String [] pva = el[i].split("=", 2);
+ String pn = pva[0].trim();
+ String pv = null;
+ if (pva.length == 2) {
+ if (pva[1].length() > 1 && pva[1].charAt(0) ==
'"') {
+ pv = pva[1].substring(1, pva[1].length() - 1);
+ }
+ else
+ pv = pva[1];
+ }
+ if (bodyLines.size() == 1 && pv == null && el.length
== 1)
+ gr.addParameter("?", pn);
+ else
+ gr.addParameter(pn, pv);
+ }
+ }
+ grL.add(gr);
+ } catch (Exception e) {
+ errorCode = EINVAL;
+ responseType = ResponseType.UnknownError;
+ errorDescription = e.getMessage();
+ }
+
+ }
+
+ public LinkedList<GenericResource> getResources()
+ {
+ return grL;
+ }
+
+ public boolean isOk()
+ {
+ return responseType == ResponseType.Ok ||
+ responseType == ResponseType.Empty;
+ }
+
+ public boolean isEmpty()
+ {
+ return responseType == ResponseType.Empty;
+ }
+
+ public boolean isError()
+ {
+ return errorCode != 0;
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ResponseBodyParser.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/ResponseType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/ResponseType.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/ResponseType.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,43 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * Response type enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum ResponseType
+{
+ Unparsed,
+ Empty,
+ Ok,
+ ProtocolError,
+ Error,
+ UnknownError,
+ UnknownType,
+ UnknownResource;
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/ResponseType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/Server.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/Server.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/Server.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,78 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Server resource object
+ *
+ * @author Mladen Turk
+ *
+ */
+public final class Server extends Resource
+{
+ public Parameter ServerName = addParameter("ServerName",
true, ParameterType.String);
+ public Parameter ServerRoot = addParameter("ServerRoot",
true, ParameterType.String);
+ public Parameter ServerVersion = addParameter("ServerVersion",
true, ParameterType.String);
+ public Parameter ServerVersionNumber =
addParameter("ServerVersionNumber", true, ParameterType.IntegerArray);
+ public Parameter ServerBuilt = addParameter("ServerBuilt",
true, ParameterType.String);
+ public Parameter ServerArchitecture =
addParameter("ServerArchitecture", true, ParameterType.String);
+ public Parameter ServerProcessing =
addParameter("ServerProcessing", true, ParameterType.String);
+ public Parameter ServerPlatform =
addParameter("ServerPlatform", true, ParameterType.String);
+ public Parameter ThreadsPerChild =
addParameter("ThreadsPerChild", true, ParameterType.Integer);
+ public Parameter MaxRequestsPerChild =
addParameter("MaxRequestsPerChild", true, ParameterType.Integer);
+ public Parameter MaxClients = addParameter("MaxClients",
true, ParameterType.Integer);
+ public Parameter Listen = addParameter("Listen",
true, ParameterType.StringArray);
+ public Parameter ListenBackLog = addParameter("ListenBackLog",
true, ParameterType.Integer);
+ public Parameter CurrentTime = addParameter("CurrentTime",
true, ParameterType.Date);
+ public Parameter RestartTime = addParameter("RestartTime",
true, ParameterType.Date);
+ public Parameter ServerUpTime = addParameter("ServerUpTime",
true, ParameterType.Long);
+ public Parameter AccessCount = addParameter("AccessCount",
true, ParameterType.Long);
+ public Parameter BytesServed = addParameter("BytesServed",
true, ParameterType.Long);
+ public Parameter Busy = addParameter("Busy",
true, ParameterType.Integer);
+ public Parameter LimitRequestFields =
addParameter("LimitRequestFields", true, ParameterType.Integer);
+ public Parameter LimitRequestFieldSize =
addParameter("LimitRequestFieldSize", true, ParameterType.Integer);
+ public Parameter ConfigurationFile =
addParameter("ConfigurationFile", true, ParameterType.String);
+
+ public ResourceType getResourceType() { return ResourceType.Server; }
+ public String getResourceName() { return resourceName; }
+ public Resource getResourceParent() { return null; }
+
+ private String resourceName = "Server";
+
+ private Server()
+ {
+ // Disable creation of unlinked resource
+ }
+
+ protected Server(ManagedServer managedServer)
+ {
+ super(managedServer, Default.SERVER_ID);
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/Server.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/StateMode.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/StateMode.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/StateMode.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,64 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha;
+
+/**
+ * StateMode enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public enum StateMode
+{
+ Unknown( "-"),
+ Active( "A"),
+ Busy( "B"),
+ Disabled( "D"),
+ Idle( "I"),
+ Stopped( "S"),
+ Error( "E");
+
+ private String value;
+ private StateMode(String v)
+ {
+ value = v;
+ }
+
+ public String valueOf()
+ {
+ return value;
+ }
+
+ public static StateMode valueOfIgnoreCase(String name)
+ {
+ for (StateMode e : values()) {
+ if (e.value.equalsIgnoreCase(name))
+ return e;
+ else if (e.name().equalsIgnoreCase(name))
+ return e;
+ }
+ return StateMode.Unknown;
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/StateMode.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseEventType.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseEventType.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseEventType.java 2008-05-28
15:47:01 UTC (rev 1630)
@@ -0,0 +1,62 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.advertise;
+
+/**
+ * Set what type of event the AdvertiseEvent signals.
+ * @param type The type of event. One of:
+ * <PRE>
+ * ON_NEW_SERVER -- New AdvertisedServer detected
+ * ON_STATUS_CHANGE -- AdvertisedServer server changed status
+ * </PRE>
+ */
+public enum AdvertiseEventType
+{
+ /** New AdvertisedServer detected */
+ ON_NEW_SERVER( 0),
+ /** AdvertisedServer server changed status */
+ ON_STATUS_CHANGE( 1);
+
+ private int value;
+ private AdvertiseEventType(int v)
+ {
+ value = v;
+ }
+
+ public int valueOf()
+ {
+ return value;
+ }
+
+ public static AdvertiseEventType valueOf(int value)
+ {
+ for (AdvertiseEventType e : values()) {
+ if (e.value == value)
+ return e;
+ }
+ throw new IllegalArgumentException("Invalid initializer: " + value);
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseEventType.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseListener.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseListener.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseListener.java 2008-05-28
15:47:01 UTC (rev 1630)
@@ -0,0 +1,453 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.advertise;
+
+import java.io.IOException;
+
+import java.net.InetAddress;
+import java.net.SocketAddress;
+import java.net.DatagramPacket;
+import java.net.MulticastSocket;
+import java.net.NetworkInterface;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.text.ParseException;
+import java.util.Date;
+import java.util.Locale;
+import java.util.HashMap;
+import java.util.Collection;
+
+import java.security.MessageDigest;
+import java.security.SecureRandom;
+import java.security.NoSuchAlgorithmException;
+
+
+/** AdvertiseListener
+ * Listens for Advertise messages from mod_cluster
+ *
+ * @author Mladen Turk
+ *
+ */
+public class AdvertiseListener
+{
+ /** Default port for listening Advertise messages.
+ */
+ public static int DEFAULT_PORT = 23364;
+ /** Default Multicast group address for listening Advertise messages.
+ */
+ public static String DEFAULT_GROUP = "224.0.1.105";
+
+ private static String RFC_822_FMT = "EEE, d MMM yyyy HH:mm:ss Z";
+ private int advertisePort = DEFAULT_PORT;
+ private String groupAddress = DEFAULT_GROUP;
+ private MulticastSocket ms;
+ private SimpleDateFormat df;
+ private boolean listening = true;
+ private boolean initialized = false;
+ private boolean running = false;
+ private boolean paused = false;
+ private boolean daemon = true;
+ private byte [] secure = new byte[16];
+ private String securityKey = null;
+ private MessageDigest md = null;
+
+ private HashMap<String, AdvertisedServer> servers;
+
+ private IAdvertiseEvent eventHandler;
+ private Thread workerThread;
+
+
+ private static void digestString(MessageDigest md, String s)
+ {
+ int len = s.length();
+ byte [] b = new byte[len];
+ for (int i = 0; i < len; i++) {
+ char c = s.charAt(i);
+ if (c < 127)
+ b[i] = (byte)c;
+ else
+ b[i] = '?';
+ }
+ md.update(b);
+ }
+
+ private AdvertiseListener()
+ {
+ // Do not allow creation
+ }
+
+ /** Create AdvertiseListener instance
+ * @param eventHandler The event handler that will be used for
+ * status and new server notifications.
+ */
+ public AdvertiseListener(IAdvertiseEvent eventHandler)
+ {
+ df = new SimpleDateFormat(RFC_822_FMT, Locale.US);
+ servers = new HashMap<String, AdvertisedServer>();
+ this.eventHandler = eventHandler;
+ }
+
+ /**
+ * The default is true - the control thread will be
+ * in daemon mode. If set to false, the control thread
+ * will not be daemon - and will keep the process alive.
+ */
+ public void setDaemon(boolean b)
+ {
+ daemon = b;
+ }
+
+ public boolean getDaemon()
+ {
+ return daemon;
+ }
+
+ /** Set Advertise security key
+ * @param key The key to use.<br/>
+ * Security key must match the AdvertiseKey
+ * on the advertised server.
+ */
+ public void setSecurityKey(String key)
+ throws NoSuchAlgorithmException
+ {
+ securityKey = key;
+ if (md == null)
+ md = MessageDigest.getInstance("MD5");
+ }
+
+ /** Set Advertise port
+ * @param port The UDP port to use.
+ */
+ public void setAdvertisePort(int port)
+ {
+ advertisePort = port;
+ }
+
+ public int getAdvertisePort()
+ {
+ return advertisePort;
+ }
+
+ /** Set Advertise Multicaset group address
+ * @param address The IP or host address to use.
+ */
+ public void setGroupAddress(String address)
+ {
+ groupAddress = address;
+ }
+
+ /** Get Advertise Multicaset group address
+ */
+ public String getGroupAddress()
+ {
+ return groupAddress;
+ }
+
+ /** Get Collection of all AdvertisedServer instances.
+ */
+ public Collection<AdvertisedServer> getServers()
+ {
+ return servers.values();
+ }
+
+ /** Get AdvertiseServer server.
+ * @param name Server name to get.
+ */
+ public AdvertisedServer getServer(String name)
+ {
+ return servers.get(name);
+ }
+
+ /** Remove the AdvertisedServer from the collection.
+ * @param server Server to remove.
+ */
+ public void removeServer(AdvertisedServer server)
+ {
+ servers.remove(server);
+ }
+
+ private void init()
+ throws IOException
+ {
+ ms = new MulticastSocket(advertisePort);
+ ms.setTimeToLive(16);
+ ms.joinGroup(InetAddress.getByName(groupAddress));
+ initialized = true;
+ }
+
+ private void interruptDatagramReader()
+ {
+ if (!initialized)
+ return;
+ try {
+ // Restrict to localhost.
+ ms.setTimeToLive(0);
+ DatagramPacket dp = new DatagramPacket(secure, secure.length,
+ InetAddress.getByName(groupAddress),
+ advertisePort);
+ ms.send(dp);
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
+
+ /** Start the Listener, creating listener thread.
+ */
+ public void start()
+ throws IOException
+ {
+ if (!initialized) {
+ init();
+ }
+ if (!running) {
+ SecureRandom random = new SecureRandom();
+ random.nextBytes(secure);
+ secure[0] = 0;
+ running = true;
+ paused = false;
+ listening = true;
+ AdvertiseListenerWorker aw = new AdvertiseListenerWorker();
+ workerThread = new Thread(aw);
+ workerThread.setDaemon(daemon);
+ workerThread.start();
+ }
+ }
+
+ /**
+ * Pause the listener, which will make it stop accepting new advertise
+ * messages.
+ */
+ public void pause()
+ {
+ if (running && !paused) {
+ paused = true;
+ interruptDatagramReader();
+ }
+ }
+
+
+ /**
+ * Resume the listener, which will make it start accepting new advertise
+ * messages again.
+ */
+ public void resume()
+ {
+ if (running && paused) {
+ // Genererate new private secure
+ SecureRandom random = new SecureRandom();
+ random.nextBytes(secure);
+ secure[0] = 0;
+ paused = false;
+ }
+ }
+
+
+ /**
+ * Stop the endpoint. This will cause all processing threads to stop.
+ */
+ public void stop()
+ {
+ if (running) {
+ running = false;
+ interruptDatagramReader();
+ workerThread = null;
+ }
+ }
+
+
+ /**
+ * Deallocate listener and close sockets.
+ */
+ public void destroy()
+ throws Exception
+ {
+ if (running) {
+ stop();
+ }
+ if (initialized) {
+ ms.leaveGroup(InetAddress.getByName(groupAddress));
+ ms.close();
+ initialized = false;
+ ms = null;
+ }
+ }
+
+ private boolean verifyDigest(String digest, String server, String date)
+ {
+ if (md == null)
+ return true;
+ md.reset();
+ digestString(md, securityKey);
+ digestString(md, date);
+ digestString(md, server);
+ byte [] our = md.digest();
+ byte [] dst = new byte[digest.length() * 2];
+ for (int i = 0, j = 0; i < digest.length(); i++) {
+ char ch = digest.charAt(i);
+ dst[j++] = (byte)((ch >= 'A') ? ((ch & 0xdf) - 'A') +
10 : (ch - '0'));
+ }
+ return true;
+ }
+
+ /**
+ * True if listener is accepting the advetise messages.<br/>
+ * If false it means that listener is experiencing some
+ * network problems if running.
+ */
+ public boolean isListening()
+ {
+ return listening;
+ }
+
+
+ // ------------------------------------ AdvertiseListenerWorker Inner Class
+ private class AdvertiseListenerWorker implements Runnable
+ {
+
+ protected AdvertiseListenerWorker()
+ {
+ // Nothing
+ }
+ /**
+ * The background thread that listens for incoming Advertise packets
+ * and hands them off to an appropriate AdvertiseEvent handler.
+ */
+ public void run() {
+ byte[] buffer = new byte[512];
+ // Loop until we receive a shutdown command
+ while (running) {
+ // Loop if endpoint is paused
+ while (paused) {
+ try {
+ Thread.sleep(1000);
+ } catch (InterruptedException e) {
+ // Ignore
+ }
+ }
+ try {
+ DatagramPacket dp = new DatagramPacket(buffer, buffer.length);
+ ms.receive(dp);
+ if (!running)
+ break;
+ byte [] data = dp.getData();
+ boolean intr = false;
+ if (dp.getLength() == secure.length) {
+ int i;
+ for (i = 0; i < secure.length; i++) {
+ if (data[i] != secure[i])
+ break;
+ }
+ if (i == secure.length)
+ intr = true;
+ }
+ if (intr)
+ continue;
+ String s = new String(data, 0, dp.getLength(), "8859_1");
+ if (!s.startsWith("HTTP/1."))
+ continue;
+
+ String [] headers = s.split("\r\n");
+ String date_str = null;
+ Date date = null;
+ int status = 0;
+ String status_desc = null;
+ String digest = null;
+ String server_name = null;
+ AdvertisedServer server = null;
+ boolean added = false;
+ for (int i = 0; i < headers.length; i++) {
+ if (i == 0) {
+ String [] sline = headers[i].split(" ", 3);
+ if (sline == null || sline.length != 3)
+ break;
+ status = Integer.parseInt(sline[1]);
+ if (status < 100)
+ break;
+ status_desc = sline[2];
+ }
+ else {
+ String [] hdrv = headers[i].split(": ", 2);
+ if (hdrv == null || hdrv.length != 2)
+ break;
+ if (hdrv[0].equals("Date")) {
+ date_str = hdrv[1];
+ try {
+ date = df.parse(date_str);
+ } catch (ParseException e) {
+ date = new Date();
+ }
+ }
+ else if (hdrv[0].equals("Digest")) {
+ digest = hdrv[1];
+ }
+ else if (hdrv[0].equals("Server")) {
+ server_name = hdrv[1];
+ server = servers.get(server_name);
+ if (server == null) {
+ server = new AdvertisedServer(server_name);
+ added = true;
+ }
+ }
+ else if (server != null) {
+ server.setParameter(hdrv[0], hdrv[1]);
+ }
+ }
+ }
+ if (server != null && status > 0) {
+ if (md != null) {
+ /* We need a digest to match */
+ if (!verifyDigest(digest, server_name, date_str)) {
+ System.out.println("Digest mismatch");
+ continue;
+ }
+ }
+ server.setDate(date);
+ boolean rc = server.setStatus(status, status_desc);
+ if (added) {
+ servers.put(server_name, server);
+ // Call the new server callback
+ eventHandler.onEvent(AdvertiseEventType.ON_NEW_SERVER,
server);
+ }
+ else if (rc) {
+ // Call the status change callback
+ eventHandler.onEvent(AdvertiseEventType.ON_STATUS_CHANGE,
server);
+ }
+ }
+ listening = true;
+ } catch (IOException e) {
+ // Do not blow the CPU in case of communication error
+ listening = false;
+ try {
+ Thread.sleep(100);
+ } catch (InterruptedException x) {
+ // Ignore
+ }
+ }
+ }
+ }
+ }
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertiseListener.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertisedServer.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/advertise/AdvertisedServer.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/advertise/AdvertisedServer.java 2008-05-28 15:47:01
UTC (rev 1630)
@@ -0,0 +1,128 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.advertise;
+
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Collection;
+
+/**
+ * Advertised server instance
+ *
+ * @author Mladen Turk
+ *
+ */
+public class AdvertisedServer
+{
+ private String server;
+ private Date date;
+ private int status;
+ private String status_desc;
+ private HashMap<String, String> headers;
+
+ /** Manager-Address header */
+ public static String MANAGER_ADDRESS = "X-Manager-Address";
+ /** Manager-Url header */
+ public static String MANAGER_URL = "X-Manager-Url";
+ /** Manager-Protocol header */
+ public static String MANAGER_PROTOCOL = "X-Manager-Protocol";
+ /** Manager-Version header */
+ public static String MANAGER_VERSION = "X-Manager-Version";
+ /** Manager-Host header */
+ public static String MANAGER_HOST = "X-Manager-Host";
+
+ private AdvertisedServer()
+ {
+ // Disable creation.
+ }
+
+ protected AdvertisedServer(String server)
+ {
+ this.server = server;
+ headers = new HashMap<String, String>();
+ }
+
+ protected boolean setStatus(int status, String desc)
+ {
+ boolean rv = false;
+ status_desc = desc;
+ if (this.status == 0 ) {
+ // First time
+ this.status = status;
+ }
+ else if (this.status != status) {
+ this.status = status;
+ rv = true;
+ }
+ return rv;
+ }
+
+ /** Set the Date of the last Advertise message
+ */
+ protected void setDate(Date date)
+ {
+ this.date = date;
+ }
+
+ /** Set the Header
+ */
+ protected void setParameter(String name, String value)
+ {
+ headers.put(name, value);
+ }
+
+ /** Get Date of the last Advertise message
+ */
+ public Date getDate()
+ {
+ return date;
+ }
+
+ /** Get Status code of the last Advertise message
+ */
+ public int getStatusCode()
+ {
+ return status;
+ }
+
+ /** Get Status description of the last Advertise message
+ */
+ public String getStatusDescription()
+ {
+ return status_desc;
+ }
+
+ /** Get Advertise parameter
+ */
+ public String getParameter(String name)
+ {
+ return headers.get(name);
+ }
+
+ public String toString()
+ {
+ return server;
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/advertise/AdvertisedServer.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/advertise/IAdvertiseEvent.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/advertise/IAdvertiseEvent.java
(rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/advertise/IAdvertiseEvent.java 2008-05-28 15:47:01
UTC (rev 1630)
@@ -0,0 +1,42 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.advertise;
+
+/**
+ * Advertise Event interface
+ *
+ * @author Mladen Turk
+ *
+ */
+public interface IAdvertiseEvent
+{
+
+ /** Callback for AdvertiseServer.
+ * @param type AdvertiseEventType caused by this event.
+ * @param server AdvertisedServer causing this event.
+ */
+ public void onEvent(AdvertiseEventType type, AdvertisedServer server);
+
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/advertise/IAdvertiseEvent.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/util/Base64.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/util/Base64.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/util/Base64.java 2008-05-28 15:47:01 UTC (rev
1630)
@@ -0,0 +1,98 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.util;
+
+import java.io.UnsupportedEncodingException;
+import org.jboss.aloha.*;
+
+/**
+ * Base64 encoding enumeration
+ *
+ * @author Mladen Turk
+ *
+ */
+public class Base64
+{
+
+ private Base64()
+ {
+ // Disable creation
+ }
+
+ private static final char[] basis64 = {
+ 'A', 'B', 'C', 'D', 'E', 'F',
'G', 'H', 'I', 'J',
+ 'K', 'L', 'M', 'N', 'O', 'P',
'Q', 'R', 'S', 'T',
+ 'U', 'V', 'W', 'X', 'Y', 'Z',
'a', 'b', 'c', 'd',
+ 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x',
+ 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7',
+ '8', '9', '+', '/'
+ };
+
+ /**
+ * Encode byte array using Base64 encoding
+ */
+ public static String encode(byte [] data, int offset, int len)
+ {
+ int i;
+ StringBuffer sb = new StringBuffer();
+ for (i = 0; i < len - 2; i += 3) {
+ sb.append(basis64[(data[offset + i] >> 2) & 0x3F]);
+ sb.append(basis64[((data[offset + i] & 0x3) << 4) |
+ ((int)(data[offset + i + 1] & 0xF0) >> 4)]);
+ sb.append(basis64[((data[offset + i + 1] & 0xF) << 2) |
+ ((int)(data[offset + i + 2] & 0xC0) >> 6)]);
+ sb.append(basis64[data[offset + 2] & 0x3F]);
+
+ }
+ if (i < len) {
+ sb.append(basis64[(data[offset + i] >> 2) & 0x3F]);
+ if (i == (len - 1)) {
+ sb.append(basis64[((data[offset + i] & 0x3) << 4)]);
+ sb.append('=');
+ }
+ else {
+ sb.append(basis64[((data[offset + i] & 0x3) << 4) |
+ ((int) (data[offset + i + 1] & 0xF0) >> 4)]);
+ sb.append(basis64[((data[offset + i + 1] & 0xF) << 2)]);
+ }
+ sb.append('=');
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Encode String using Base64 encoding
+ */
+ public static String encode(String string)
+ {
+ try {
+ byte [] data = string.getBytes(Default.CHARSET);
+ return encode(data, 0, data.length);
+ } catch (UnsupportedEncodingException e) {
+ return "";
+ }
+ }
+}
Property changes on: sandbox/aloha/java/org/jboss/aloha/util/Base64.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/org/jboss/aloha/util/Utils.java
===================================================================
--- sandbox/aloha/java/org/jboss/aloha/util/Utils.java (rev 0)
+++ sandbox/aloha/java/org/jboss/aloha/util/Utils.java 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,131 @@
+/*
+ *
+ * Copyright(c) 2008 Red Hat Middleware, LLC,
+ * and individual contributors as indicated by the @authors tag.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library in the file COPYING.LIB;
+ * if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+ *
+ */
+
+package org.jboss.aloha.util;
+
+import java.io.PrintStream;
+import java.util.Random;
+
+/**
+ * General purpose utilities.
+ *
+ * @author Mladen Turk
+ */
+public final class Utils
+{
+
+ private Utils()
+ {
+ // Private to prevent creation.
+ }
+
+ private static long counter = 1024L;
+ private static long timer = System.currentTimeMillis();
+ private static Random rnd = new Random(timer);
+
+ /**
+ * Returns the unique 64 bit id.
+ * Values lower then 1024 are reseved for system ID's.
+ */
+ public static long Id()
+ {
+ long id;
+ synchronized (Utils.class) {
+ id = counter++;
+ }
+ return id;
+ }
+
+ public static void generateRandom(byte[] dst)
+ {
+ rnd.nextBytes(dst);
+ }
+
+ public static String hex(byte val)
+ {
+ String h = Integer.toHexString(val);
+ if (h.length() == 1)
+ h = "0" + h;
+ return h;
+ }
+
+ public static String hex(short val)
+ {
+ String h = Integer.toHexString(val);
+ return ("0000" + h).substring(h.length());
+ }
+
+ public static String hex(int val)
+ {
+ String h = Integer.toHexString(val);
+ return ("00000000" + h).substring(h.length());
+ }
+
+ public static String hex(long val)
+ {
+ String h = Long.toHexString(val);
+ return ("0000000000000000" + h).substring(h.length());
+ }
+
+ public static String dumpBuffer(byte[] data, int offset, int len)
+ {
+ int i;
+ int p = offset;
+
+ if (offset >= data.length)
+ return null;
+ StringBuffer sb = new StringBuffer();
+ sb.append(hex((short)offset));
+ sb.append(": ");
+ for (i = 0; i < 16; i++) {
+ if (i < data.length) {
+ sb.append(hex(data[offset+i]));
+ if (i == 7)
+ sb.append("|");
+ else
+ sb.append(" ");
+ }
+ else {
+ sb.append(" ");
+ }
+ }
+ sb.append(" | ");
+ for (i = offset; i < offset + 16; i++) {
+ if (i < data.length) {
+ if (!Character.isISOControl((char)data[i]))
+ sb.append(new Character((char)data[i]));
+ else
+ sb.append(".");
+ }
+ }
+ return sb.toString();
+ }
+
+ public static void dumpBuffer(byte[] data, int offset, int len, PrintStream out)
+ {
+ out.println(dumpBuffer(data, offset, len));
+ }
+
+}
+
Property changes on: sandbox/aloha/java/org/jboss/aloha/util/Utils.java
___________________________________________________________________
Name: svn:eol-style
+ native
Added: sandbox/aloha/java/overview.html
===================================================================
--- sandbox/aloha/java/overview.html (rev 0)
+++ sandbox/aloha/java/overview.html 2008-05-28 15:47:01 UTC (rev 1630)
@@ -0,0 +1,35 @@
+<!--
+ ALOHA
+
+ Copyright(c) 2008 Red Hat Middleware, LLC,
+ and individual contributors as indicated by the @authors tag.
+ See the copyright.txt in the distribution for a
+ full listing of individual contributors.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library in the file COPYING.LIB;
+ if not, write to the Free Software Foundation, Inc.,
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+-->
+<html>
+<head>
+<title>Overview Documentation for Aloha</title>
+</head>
+<body bgcolor="white">
+ <p>
+ The <em>Aloha</em> component.
+ </p>
+
+</body>
+</html>
Property changes on: sandbox/aloha/java/overview.html
___________________________________________________________________
Name: svn:eol-style
+ native