001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019:
020: package samples.services;
021:
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axis2.context.OperationContext;
024: import org.apache.axis2.context.ServiceContext;
025:
026: import javax.xml.namespace.QName;
027:
028: public class LBService2 {
029:
030: private ServiceContext serviceContext = null;
031:
032: public void init(ServiceContext serviceContext) {
033: this .serviceContext = serviceContext;
034: }
035:
036: public OMElement sleepOperation(OMElement topParam) {
037:
038: topParam.build();
039: topParam.detach();
040:
041: OMElement param = topParam.getFirstChildWithName(new QName(
042: "load"));
043: String l = param.getText();
044: long time = Long.parseLong(l);
045:
046: try {
047: Thread.sleep(time);
048: } catch (InterruptedException e) {
049: e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
050: }
051:
052: Long c = null;
053: Object o = serviceContext.getProperty("count");
054: if (o == null) {
055: c = new Long(1);
056: serviceContext.setProperty("count", c);
057: } else {
058: c = (Long) o;
059: c = new Long(c.longValue() + 1);
060: serviceContext.setProperty("count", c);
061: }
062:
063: String cName = "anonymous";
064: Object cn = serviceContext.getProperty("cName");
065: if (cn != null) {
066: cName = (String) cn;
067:
068: }
069:
070: String sName = "anonymous";
071: Object s = System.getProperty("server_name");
072: if (s != null) {
073: sName = (String) s;
074: }
075:
076: String msg = "Server: " + sName + " processed the request "
077: + c.toString() + " from client: " + cName;
078: System.out.println(msg);
079:
080: param.setText(msg);
081:
082: return topParam;
083: }
084:
085: public OMElement loadOperation(OMElement topParam) {
086:
087: topParam.build();
088: topParam.detach();
089:
090: OMElement param = topParam.getFirstChildWithName(new QName(
091: "load"));
092: String l = param.getText();
093: long load = Long.parseLong(l);
094:
095: for (long i = 0; i < load; i++) {
096: System.out.println("Iteration: " + i);
097: }
098:
099: Long c = null;
100: Object o = serviceContext.getProperty("count");
101: if (o == null) {
102: c = new Long(1);
103: serviceContext.setProperty("count", c);
104: } else {
105: c = (Long) o;
106: c = new Long(c.longValue() + 1);
107: serviceContext.setProperty("count", c);
108: }
109:
110: String cName = "anonymous";
111: Object cn = serviceContext.getProperty("cName");
112: if (cn != null) {
113: cName = (String) cn;
114:
115: }
116:
117: String sName = "anonymous";
118: Object s = System.getProperty("server_name");
119: if (s != null) {
120: sName = (String) s;
121: }
122:
123: String msg = "Server: " + sName + " processed the request "
124: + c.toString() + " from client: " + cName;
125: System.out.println(msg);
126:
127: param.setText(msg);
128:
129: return topParam;
130: }
131:
132: public OMElement setClientName(OMElement name) {
133:
134: name.build();
135: name.detach();
136:
137: String cName = name.getText();
138: serviceContext.setProperty("cName", cName);
139:
140: String sName = "anonymous";
141: Object s = System.getProperty("server_name");
142: if (s != null) {
143: sName = (String) s;
144: }
145:
146: String msg = "Server " + sName
147: + " started a session with client " + cName;
148: System.out.println(msg);
149: name.setText(msg);
150:
151: return name;
152: }
153: }
|