Skip to content

Commit aa123a9

Browse files
committed
增加加速器
1 parent 0c354c3 commit aa123a9

File tree

11 files changed

+168
-63
lines changed

11 files changed

+168
-63
lines changed

conf/nbs-conf.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ nbs.server.address.host=127.0.0.1
1616
nbs.server.address.api-port=5001
1717
nbs.server.address.gateway-port=8080
1818
nbs.server.exit.stop=false
19-
nbs.server.integrated.enabled=true
19+
nbs.server.integrated.enabled=false
2020

2121
# IP CHECKED
2222
nbs.server.ip.checked-url=http://www.net.cn/static/customercare/yourip.asp

conf/nbs.db

0 Bytes
Binary file not shown.

src/main/java/io/nbs/client/Launcher.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,4 +385,8 @@ public static void destoryIPFS(){
385385
public static boolean isIpfsRuning() {
386386
return ipfsRuning;
387387
}
388+
389+
public static String getSysUser(){
390+
return System.getProperty("user.name","");
391+
}
388392
}

src/main/java/io/nbs/client/ui/panels/im/IMFileActionListener.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import io.nbs.client.exceptions.FileTooLargeException;
88
import io.nbs.client.listener.IPFSFileUploader;
99
import io.nbs.client.ui.frames.MainFrame;
10+
import io.nbs.client.ui.panels.im.messages.MessageEditorPanel;
1011
import io.nbs.commons.helper.DateHelper;
1112
import io.nbs.commons.utils.DataSizeFormatUtil;
1213
import io.nbs.sdk.beans.PeerInfo;
@@ -19,6 +20,7 @@
1920
import java.awt.event.ActionEvent;
2021
import java.awt.event.ActionListener;
2122
import java.io.File;
23+
import java.util.concurrent.atomic.AtomicInteger;
2224

2325
/**
2426
* @Package : io.nbs.client.ui.panels.im
@@ -33,6 +35,9 @@ public class IMFileActionListener implements ActionListener {
3335

3436
private IPFSFileUploader fileUploader;
3537
private AttachmentInfoService attachmentInfoService;
38+
private MessageEditorPanel editorPanel;
39+
private AtomicInteger uploading = new AtomicInteger(0);
40+
private String upfileName = "";
3641

3742
private JFileChooser jFileChooser;
3843
public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChooser, SqlSession sqlSession) {
@@ -41,20 +46,36 @@ public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChoo
4146
attachmentInfoService = new AttachmentInfoService(sqlSession);
4247
}
4348

49+
public IMFileActionListener(IPFSFileUploader fileUploader, JFileChooser fileChooser, SqlSession sqlSession, MessageEditorPanel editorPanel) {
50+
this.editorPanel = editorPanel;
51+
this.fileUploader = fileUploader;
52+
this.jFileChooser = fileChooser;
53+
attachmentInfoService = new AttachmentInfoService(sqlSession);
54+
}
55+
4456
@Override
4557
public void actionPerformed(ActionEvent e) {
58+
if(uploading.intValue()==1){
59+
JOptionPane.showMessageDialog(MainFrame.getContext(),"正在上传文件["+upfileName+"],请稍后再传...");
60+
return;
61+
}
4662
this.jFileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
4763
this.jFileChooser.showDialog(Launcher.getContext().getCurrentFrame(),"选择");
4864
File selection = jFileChooser.getSelectedFile();
4965
if(selection==null)return;
66+
this.upfileName = selection.getName();
5067
logger.info("{}在{}分享了{}",MainFrame.getContext().getCurrentPeer().getNick(),DateHelper.currentTime(),selection.getAbsolutePath());
5168
if(selection.length()>200*1024*1024){
52-
JOptionPane.showMessageDialog(MainFrame.getContext(),"成功加入分享任务,由于文件较大需要稍等一会儿返回唯一串码.");
69+
//JOptionPane.showMessageDialog(MainFrame.getContext(),"成功加入分享任务,由于文件较大需要稍等一会儿返回唯一串码.");
70+
editorPanel.setTipLabel("正在上传["+selection.getName()+"]请稍后...",true);
5371
}
72+
uploading.set(1);
5473
new Thread(()->{
5574
try {
5675
MerkleNode node = fileUploader.addFileToIPFS(selection);
5776
logger.info("添加文件成功.{}",selection.getName());
77+
editorPanel.setTipLabel(null,false);
78+
uploading.set(0);
5879
new Thread(()->{
5980
saveUploadFileInfo2DB(node);
6081
}).start();

src/main/java/io/nbs/client/ui/panels/im/messages/MessageEditorPanel.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ public class MessageEditorPanel extends ParentAvailablePanel {
3939
*/
4040
private JPanel controlLabel;
4141

42+
private static MessageEditorPanel context;
43+
4244
private JLabel fileLabel;
4345
private JLabel expressionLabel;
4446
private JLabel cutLabel;
@@ -58,15 +60,17 @@ public class MessageEditorPanel extends ParentAvailablePanel {
5860

5961
private JFileChooser jFileChooser;
6062
private IMFileActionListener imFileActionListener;
63+
private JLabel msgTipLabel;
6164

6265
/**
6366
*
6467
* @param parent
6568
*/
6669
public MessageEditorPanel(JPanel parent, IPFSFileUploader uploader) {
6770
super(parent);
71+
context = this;
6872
jFileChooser = new JFileChooser();
69-
imFileActionListener = new IMFileActionListener(uploader,jFileChooser,Launcher.getSqlSession());
73+
imFileActionListener = new IMFileActionListener(uploader,jFileChooser,Launcher.getSqlSession(),context);
7074
initComponents();
7175
initView();
7276
setListeners();
@@ -128,6 +132,9 @@ private void initComponents(){
128132
cutTip
129133
);
130134

135+
msgTipLabel = new JLabel();
136+
137+
131138
textEditor = new NBSTextEditor();
132139
textEditor.setBackground(ColorCnst.WINDOW_BACKGROUND);
133140
textEditor.setFont(FontUtil.getDefaultFont(14));
@@ -155,11 +162,22 @@ private void initComponents(){
155162

156163
private void initView(){
157164
this.setLayout(new GridBagLayout());
165+
//提示
166+
msgTipLabel.setHorizontalAlignment(JLabel.RIGHT);
167+
msgTipLabel.setBackground(ColorCnst.WINDOW_BACKGROUND);
168+
msgTipLabel.setForeground(ColorCnst.RED);
169+
msgTipLabel.setVisible(false);
170+
171+
msgTipLabel.setFont(FontUtil.getDefaultFont(10));
172+
158173
controlLabel.add(expressionLabel);
159174
controlLabel.add(fileIcon);
175+
controlLabel.add(msgTipLabel);
160176
//隐藏截图
161177
//controlLabel.add(cutIcon);
162178

179+
180+
163181
add(controlLabel,new GBC(0,0).setFill(GBC.HORIZONTAL).setWeight(1,1));
164182
add(textScrollPane,new GBC(0,1).setFill(GBC.BOTH).setWeight(1,15));
165183
add(sendPanel,new GBC(0,2)
@@ -258,4 +276,10 @@ public NBSButton getSendButton() {
258276
}
259277

260278

279+
public void setTipLabel(String msg,boolean visabled){
280+
if(msg==null)msg="";
281+
this.msgTipLabel.setText(msg);
282+
this.msgTipLabel.setVisible(visabled);
283+
this.controlLabel.updateUI();
284+
}
261285
}

src/main/java/io/nbs/client/ui/panels/manage/MMBodyPanel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ private void setListeners() {
107107
*/
108108
public void showPanel(MMNames who){
109109
if(who==MMNames.TIP){
110-
MMMonitPanel.CtrlSign = true;
110+
MMMonitPanel.setCtrlSign(true);
111111
}else {
112112
tipResultHashPanel.hideMMMonitor();
113-
MMMonitPanel.CtrlSign = false;
113+
MMMonitPanel.setCtrlSign(false);
114114
}
115115
cardLayout.show(cardPanel,who.name());
116116
}

src/main/java/io/nbs/client/ui/panels/manage/MMSearcherPanel.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ private void searchHash(final String text){
182182
if(tipResultHashPanel.prevousHash().equals(text))return;
183183
tipResultHashPanel.setHash(multihash.toBase58());
184184
new Thread(()->{
185+
if( tipResultHashPanel.getMonitPanel()!=null){
186+
tipResultHashPanel.getMonitPanel().stopMonitor();
187+
}
185188
Multihash multihash1= Multihash.fromBase58(text);
186189
long start = System.currentTimeMillis();
187190
try {
@@ -190,13 +193,15 @@ private void searchHash(final String text){
190193
String json = JSONParser.toString(o);
191194
BlockStat stat = JSON.parseObject(json,BlockStat.class);
192195
long usedsecd = System.currentTimeMillis()-start;
193-
logger.info("TESTLOG>>>查找文件:{},用时{}",text,DateHelper.calcUsedTime(usedsecd));
196+
logger.info("客户端IP{}用时{}ms",MainFrame.getContext().getCurrentPeer().getIp(),usedsecd);
197+
logger.info("TESTLOG:{}>>>查找文件:{},用时{}",Launcher.getSysUser(),text,DateHelper.calcUsedTime(usedsecd));
194198
tipResultHashPanel.setBlkStat(stat,null,usedsecd);
195199
} catch (IOException e) {
196200
e.printStackTrace();
197201
logger.error(e.getMessage());
198202
String error = "没有在NBS网络世界查到你要的数据["+multihash1.toBase58()+"]";
199203
long usedsecd = System.currentTimeMillis()-start;
204+
logger.info("TESTLOG:{}>>>查找文件:{}没有查到,用时{}",Launcher.getSysUser(),text,DateHelper.calcUsedTime(usedsecd));
200205
tipResultHashPanel.setBlkStat(null,error,usedsecd);
201206
}
202207
}).start();

0 commit comments

Comments
 (0)