📄 ecmserver.java
字号:
int l=services.length;
sorder=1;
srs=tt.recordSql("select * from service");
//deal with the service sequence
outLoop:
for (sorder=1;sorder<l;sorder++){
System.out.println("sorder: "+sorder);
System.out.println("sorder length: "+l);
once=services[sorder][8];
System.out.println("once="+once);
/***test***
String s1=new String("yes");
if (once.equals(s1)){
System.out.println("s1="+s1);
System.out.println("once before while="+once+"..");
}
//***end test***/
srs.next();
System.out.println("srs next()");
try{ cnum=srs.getLong("num");
}
catch(Exception e){ System.out.println("srs.getLong()");
}
System.out.println("get num: "+cnum);
no=0;
////////
System.out.println("");
System.out.println("-------enter a new service-------");
System.out.println(System.currentTimeMillis());
if (services[sorder][1]==null ){
tt.closeResult();
break outLoop;
}
////////
else {
//long servetime=Long.parseLong(services[sorder][7]);cycletime=Double.valueOf(rs.getString("cycle") ).doubleValue();
double servetime=Double.valueOf(services[sorder][7] ).doubleValue();
System.out.println("service time is :"+servetime);
///////超过给定服务时间则删除该服务
if (servetime<repeattime){
aglet.log.Add("event","ecmserver:servetime("+servetime+") outdate and will del ");
tt.recordDelete("delete from service where service.servetime='"+servetime+"'");
System.out.println("delete from service where service.servetime='"+servetime+"'");
}
///////在规定服务时间内则执行该服务
else {
sgoodsname=services[sorder][3];
smodel=services[sorder][4];
sprice=services[sorder][5];
samount=services[sorder][6];
String condition=" where goodsname='"+sgoodsname+"'";
if (!smodel.equals(""))
condition=condition+" and model='"+smodel+"'";
if (!sprice.equals("0"))
condition=condition+" and model"+sprice;
if (!samount.equals("0"))
condition=condition+" and amount"+samount;
System.out.println("the condition is:"+condition);
//////////查询是否有新信息
rs=tt.recordSql("select * from goods "+condition);
System.out.println("select * from goods "+condition);
System.out.println("go on");
System.out.println("go on");
System.out.println("go on");
rsmd=rs.getMetaData();
numCols=rsmd.getColumnCount();
goods=new String[100][numCols-1+1];
//display each column title
for (int i=1;i<=numCols-1;i++){
goods[no][i-1]=rsmd.getColumnLabel(i);
}
goods[no][numCols-1]="source";
//////////////
System.out.println("query result got");
//****check the good in the goods table****
while (rs.next()){
String s1=new String("yes");
if (once.equals(s1)){
System.out.println("************1");
//goods[no][numCols-1]="source";
String gtime=rs.getString("goodstime");
goodstime=Double.valueOf(gtime).doubleValue();
//System.out.println("goods time is :"+goodstime);
long ggtime=(long)goodstime;
java.util.Date gdate=new java.util.Date(ggtime);
String sdate=gdate.toString();
System.out.println("goods time is :"+sdate);
no++;
for(int i=1;i<numCols-1;i++){
//if (i>1) System.out.print(",");
tmpstr=rs.getString(i);
if(rs.wasNull()){
goods[no][i-1]="NULL";
//System.out.print(goods[no][i-1]);
}
else {
goods[no][i-1]=tmpstr;
//System.out.print("****"+goods[no][i-1]);
}
}///end for
goods[no][numCols-2]=gtime;
//goods[no][numCols-2]=sdate;
goods[no][numCols-1]=aglet.surl;
//**** change the once tag in the service table
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
scon=DriverManager.getConnection("jdbc:odbc:"+"Ecmdb");
}
catch(ClassNotFoundException e){
System.out.println("ClassNotFoundExeption in once tag changing");
}
catch(SQLException ex){
System.out.println("\n***SQLException caught in once tag changing***\n");
while (ex != null){
System.out.println("SQLState:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
}
try{
PreparedStatement spstm;
spstm=scon.prepareStatement("UPDATE service SET once='no' WHERE num=?");
//spstm=scon.prepareStatement("update comment set url=?,comment=? where comment.no=8");
spstm.setInt(1,(int)cnum);
spstm.executeUpdate();
spstm.close();
scon.close();
}
catch(SQLException ex){
System.out.println("\n***SQLException caught in once tag changing***\n");
while (ex != null){
System.out.println("SQLState:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
}
//**** end change****
}//end if
else{
System.out.println("************11");
String gtime=rs.getString("goodstime");
//goodstime=Long.parseLong(gtime);
goodstime=Double.valueOf(gtime).doubleValue();
//System.out.println("goods time is :"+goodstime);
long ggtime=(long)goodstime;
java.util.Date gdate=new java.util.Date(ggtime);
String sdate=gdate.toString();
System.out.println("goods time is :"+sdate);
//if ( repeattime-goodstime<=(15*1000*aglet.cycletime)){ ///cycletiem单位为分钟
if ((preRepeattime<=goodstime)&&(goodstime<=repeattime)){ ///cycletiem单位为分钟
no++;
//System.out.println("the no is:"+no);
//display each column data, "numCols-1 " means not include "descirbe"
for(int i=1;i<numCols-1;i++){
//if (i>1) System.out.print(",");
tmpstr=rs.getString(i);
if(rs.wasNull()){
goods[no][i-1]="NULL";
//System.out.print(goods[no][i-1]);
}
else {
goods[no][i-1]=tmpstr;
//System.out.print("****"+goods[no][i-1]);
}
}///end for
goods[no][numCols-2]=gtime;
//goods[no][numCols-2]=sdate;
goods[no][numCols-1]=aglet.surl;
}///end if
}///end else
}//end while
rs.close();
//////////将查询到的新信息返回给客户
int l2=goods.length;
int ll=goods[1].length;
//System.out.println("array lenth is :"+l2);
//System.out.println("record lenth is :"+ll);
if (l2<2)
System.out.println("sorry,there is no a new goods");
else {
URL urlClient=null;
AgletID idClient;
System.out.println("-------enter send result--------");
//System.out.println("the sorder is:"+sorder);
//System.out.println("ecmClient url are: "+services[sorder][1]);
try{
urlClient=new URL(services[sorder][1]);
System.out.println("ecmClient id are: "+services[sorder][2]);
}
catch(java.net.MalformedURLException ex){
System.out.println("****java.net.MalformedURLException****");
ex.printStackTrace();
}
try{
idClient=new AgletID(services[sorder][2]);
ecmClient = aglet.getAgletContext().getAgletProxy(urlClient, idClient);
ecmClient.sendAsyncMessage(new Message("getResult",goods));
}
catch(InvalidAgletException ex){
System.out.println("****InvalidAgletException****");
aglet.log.Add("error","ecmserver:InvalidAglet("+services[sorder][2]+"),fail to send reseult and will del it");
tt.recordDelete("delete from service where service.cid='"+services[sorder][2]+"'");
System.out.println("delete from service where service.cid='"+services[sorder][2]+"'");
ex.printStackTrace();
}
//tt.closeResult();
}
}///end else2
}///end else3
}///end for
//tt.closeConnect();
System.out.println("-------i will sleep "+60*1000*(long)aglet.cycletime*0.2+" milli second--------");
long sleeptime=12*1000*(long)aglet.cycletime;
//sleep(60*1000*(long)aglet.cycletime);
//sleep(sleeptime);
sleep(sleeptime);
}///end try
catch(SQLException ex){
System.out.println("\n***SQLException caught in while***\n");
while (ex != null){
System.out.println("SQLState:"+ex.getSQLState());
System.out.println("Message:"+ex.getMessage());
System.out.println("Vendor:"+ex.getErrorCode());
ex=ex.getNextException();
System.out.println("");
}
aglet.log.Add("error","ecmserver:query date in this service");
}
catch(NumberFormatException ex){
System.out.println("\n***NumberFormatException caught in while***\n");
ex.printStackTrace();
aglet.log.Add("error","ecmserver:FormatException ");
}
catch(InterruptedException ex){
System.out.println("\n***InterruptedException caught in while***\n");
ex.printStackTrace();
aglet.log.Add("error","ecmserver:Interrupted");
}
System.out.println("New");
System.out.print("time to old: ");
System.out.println(goodstime-repeattime);
//repeattime=System.currentTimeMillis()-3*60*1000;
preRepeattime=repeattime;
repeattime=System.currentTimeMillis();
//srs.close();
tt.closeResult();
}///end while
//tt.closeConnect();
}///end function
//////////
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -