Read and Write of multiple file servers. SMB protocol can be used here.
Static Page, use freemarker open-source framework
If a large number of read/write requests are taken into account, the requests are distributed or scheduled.
First, we should consider the ing between the file server and the static page, that is, the server to which the file should be read and written. The simplest way to do this is random ing, then save the ing to the database. The common SMB operation code is as follows:
Copy codeThe Code is as follows:
Public static boolean exists (String filepath, String username, String pwd) throws Exception
{
SmbFile file = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
Try {
Return file. exists ();
} Catch (Exception ex ){
Return false;
}
}
Public static boolean fileRename (String filepath, String newFilename, String username, String pwd)
{
Try {
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (f. isFile ()){
String str = filepath. substring (0, filepath. lastIndexOf ("/"));
Str = "smb: //" + username + ":" + pwd + "@" + str + "/" + newFilename;
F. renameTo (new SmbFile (str ));
} Else if (f. isDirectory ()){
String str = filepath. substring (0, filepath. length ()-1 );
Str = filepath. substring (0, str. lastIndexOf ("/"));
Str = "smb: //" + username + ":" + pwd + "@" + str + "/" + newFilename;
F. renameTo (new SmbFile (str ));
}
Return true;
} Catch (Exception ex ){
Return false;
}
}
Public static void mkdir (String dir, String username, String pwd)
{
Try {
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + dir );
If (! F. exists ())
F. mkdir ();
} Catch (Exception ex)
{
}
}
Public static void mkfile (String filepath, String username, String pwd)
{
Try
{
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (! F. exists ())
F. createNewFile ();
} Catch (Exception ex)
{
}
}
Public static void mkfile (String filepath, String username, String pwd, String content)
{
Try
{
SmbFile f = new SmbFile ("smb: //" + username + ":" + pwd + "@" + filepath );
If (! F. exists ())
F. createNewFile ();
WriteFile (filepath, content, username, pwd );
} Catch (Exception ex)
{
}
}
Public static boolean isdir (String filepath, String username, String pwd) throws Exception
{
String dir = "smb: //" + username + ":" + pwd + "@" + filepath;
SmbFile f = new SmbFile (dir );
Return f. isDirectory ();
}
Second, static pages can be generated by freemarker. The use of freemarker is relatively simple. I will not say it again.
Third, the scheduling center, or the static request is saved to the Task first, and then executed asynchronously through the scheduling center, which can be solved by another article I mentioned in my blog.