Gather采集类:
package com.briup.woss.client.impl;
import java.io.*;ClientImpl类:
package com.briup.woss.client.impl;
import java.io.*;
import java.net.Socket;
import java.util.*;
import com.briup.pojos.BIDR;
import com.briup.util.impl.ConfigurationImpl;
import com.briup.woss.client.Client;
import com.briup.woss.client.Gather;
public class ClientImpl implements Client {
public void send(Collection<BIDR> c) throws Exception {
Socket client=new Socket("127.0.0.1",9001);
ObjectOutputStream object=new ObjectOutputStream(client.getOutputStream());
object.writeObject(c);
}
public void setProperties(Properties pop) {
}
}
client端的Main类:
package com.briup.woss.client;
import java.util.Collection;
import com.briup.pojos.BIDR;
import com.briup.util.BackUP;
import com.briup.util.Configuration;
import com.briup.util.Logger;
import static com.briup.util.impl.ConfigurationImpl.*;
public class Main {
public static Configuration conf =getConfiguration();
public static void main(String[] args) {
Logger logger = null;
Gather gather = null;
BackUP backup = null;
Client client = null;
Collection<BIDR> con = null;
try {
logger = conf.getClientLogger();
logger.info("客户端开始启动");
gather = conf.getGather();
logger.info("准备采集");
long a=System.currentTimeMillis();
con = gather.gather();
System.out.println(System.currentTimeMillis()-a);
logger.info("采集成功");
backup = conf.getBackup();
try {
client = conf.getClient();
logger.info("准备发送 ");
client.send(con);
logger.info("发送成功!");
} catch (Exception e) {
logger.error(e.getMessage());
logger.info("准备备份");
//backup.load();
backup.store(con);
logger.info("备份成功");
}
} catch (Exception e1) {
e1.printStackTrace();
logger.error(e1.getMessage());
logger.warn("采集失败");
}
}
}
ServerImpl类:
package com.briup.woss.server.impl;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.*;
import java.io.*;
import com.briup.pojos.BIDR;
import com.briup.woss.server.DBStore;
import com.briup.woss.server.Server;
import com.sun.org.apache.xml.internal.serialize.Printer;
public class ServerImpl implements Server {
public void revicer(DBStore dbstore) throws Exception {
Collection<BIDR>c=new ArrayList<BIDR>();
ServerSocket server=new ServerSocket(9001);
Socket socket=server.accept();
ObjectInputStream object=new ObjectInputStream(socket.getInputStream());
c=(Collection)object.readObject();
for(BIDR bidr:c)
System.out.println(bidr);
dbstore.saveToDB(c);
object.close();
socket.close();
server.close();
}
public void setProperties(Properties pop) {
// TODO Auto-generated method stub
}
}
DBStoreImpl 类
package com.briup.woss.server.impl;
import static com.common.ConnectionFactory.*;
import java.sql.DriverManager;
import java.util.Collection;
import java.util.Properties;
import com.briup.pojos.BIDR;
import com.briup.woss.server.DBStore;
import java.sql.*;
public class DBStoreImpl implements DBStore {
private static Connection con;
static
{
con=getConnection();
}
public void saveToDB(Collection<BIDR> c) throws Exception{
PreparedStatement psmt=null;
CallableStatement stmt;
//设置为自动提交事物
con.setAutoCommit(false);
//插入到t_detail_x中
for(BIDR bidr:c)
{
String sql="insert into t_detail_"+bidr.getLogin_date().getDate()+" values(?,?,?,?,?,?)";
psmt=con.prepareStatement(sql);
psmt.setString(1, bidr.getAAA_login_name());
psmt.setString(2, bidr.getLogin_ip());
psmt.setTimestamp(3, bidr.getLogin_date());
psmt.setTimestamp(4, bidr.getLogout_date());
psmt.setString(5, bidr.getNAS_ip());
psmt.setInt(6, bidr.getTime_deration());
psmt.execute();
}
con.commit();
//调用daypro存储过程执行对t_day_x插入数据
stmt=con.prepareCall("{call daypro}");
stmt.execute();
//调用monthpro存储过程执行对t_month_x插入数据
stmt=con.prepareCall("{call monthpro}");
stmt.execute();
stmt.close();
//调用yearpro存储过程执行对t_year_x插入数据
/*CallableStatement stmt3=con.prepareCall("{call yearpro}");
stmt3.execute();
stmt3.close();*/
psmt.close();
con.close();
}
public void setProperties(Properties pop) {
// TODO Auto-generated method stub
}
}
server端的Main类:
package com.briup.woss.server;
import com.briup.util.Configuration;
import com.briup.util.Logger;
import static com.briup.util.impl.ConfigurationImpl.*;
public class Main {
/**
* 服务器端的程序入口
*/
public static Configuration conf =getConfiguration();
public static void main(String[] args) {
DBStore dbstore = null;
Server server = null;
Logger logger=null;
try {
dbstore = conf.getDBStore();
server = conf.getServer();
logger=conf.getServerLogger();
logger.info("服务端等待接收数据");
server.revicer(dbstore);
logger.info("服务端接收数据成功");
} catch (Exception e) {
logger.error(e.getMessage());
logger.warn("服务端接收数据失败");
}
}
}