org.csource.common.MyException Java Examples
The following examples show how to use
org.csource.common.MyException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConnectionPool.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 6 votes |
public static Connection getConnection(InetSocketAddress socketAddress) throws MyException { if (socketAddress == null) { return null; } String key = getKey(socketAddress); ConnectionManager connectionManager; connectionManager = CP.get(key); if (connectionManager == null) { synchronized (ConnectionPool.class) { connectionManager = CP.get(key); if (connectionManager == null) { connectionManager = new ConnectionManager(socketAddress); CP.put(key, connectionManager); } } } return connectionManager.getConnection(); }
Example #2
Source File: StorageClient.java From mumu with Apache License 2.0 | 6 votes |
/** * check storage socket, if null create a new connection * @param group_name the group name of storage server * @param remote_filename filename on storage server * @return true if create a new connection */ protected boolean newReadableStorageConnection(String group_name, String remote_filename) throws IOException, MyException { if (this.storageServer != null) { return false; } else { TrackerClient tracker = new TrackerClient(); this.storageServer = tracker.getFetchStorage(this.trackerServer, group_name, remote_filename); if (this.storageServer == null) { throw new MyException("getStoreStorage fail, errno code: " + tracker.getErrorCode()); } return true; } }
Example #3
Source File: ForecastAction.java From fastdfs-zyc with GNU General Public License v2.0 | 6 votes |
@ResponseBody @RequestMapping("/drawAreaAction") public List<Line> drawAreaAction(String ip) throws IOException, MyException,JSchException { List<Line> lines = new ArrayList<Line>(); Forecast forecast = getForecastObject(ip); Line line = new Line(ip); if(forecast.getIpAddr()!=null){ Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int size= (int) (forecast.getUseHour()%24==0?forecast.getUseHour()/24:forecast.getUseHour()/24+1); for (int i = 0; i <size ; i++) { c.add(Calendar.DAY_OF_MONTH, 1); Date date = c.getTime(); long useMB =( forecast.getFreeMB() - 24*forecast.getAverage() * (i))/1024; line.getData().add(new Object[]{date, useMB}); } } lines.add(line); return lines; }
Example #4
Source File: UserServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 6 votes |
@Override @Transactional(propagation = Propagation.REQUIRED) public boolean login(String name, String password) throws IOException, MyException { //To change body of implemented methods use File | Settings | File Templates. List<User> users = new ArrayList<User>(); Session session = getSession(); StringBuilder queryString = new StringBuilder("from User as u where u.name=:name and u.psword=:password"); Query query = session.createQuery(queryString.toString()); users = query.setParameter("name",name) .setParameter("password",password) .list(); boolean res=false; if(!users.isEmpty()){ res=true; } return res; }
Example #5
Source File: WarningServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 6 votes |
@Override @Transactional(propagation = Propagation.REQUIRED) public List<WarningData> findWarning(WarningData wd,PageInfo pageInfo) throws IOException, MyException { //To change body of implemented methods use File | Settings | File Templates. List<WarningData> warningDatas = new ArrayList<WarningData>(); Session session = getSession(); StringBuilder queryString = new StringBuilder("from WarningData as wd "); if(!StringUtils.isNullOrEmpty(wd.getWdIpAddr())){ queryString.append("where wd.wdIpAddr like '%"+wd.getWdIpAddr()+"%'"); } Query query = session.createQuery(queryString.toString()); pageInfo.setTotalCount(query.list().size()); query.setMaxResults(pageInfo.getNumPerPage()); query.setFirstResult((pageInfo.getPageNum()-1)*pageInfo.getNumPerPage()); warningDatas = query.list(); return warningDatas; }
Example #6
Source File: StorageClient1.java From mumu with Apache License 2.0 | 5 votes |
/** * upload appender file to storage server (by file name) * @param group_name the group name to upload file to, can be empty * @param local_filename local filename to upload * @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename * @param meta_list meta info array * @return file id(including group name and filename) if success, <br> * return null if fail */ public String upload_appender_file1(String group_name, String local_filename, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException { String parts[] = this.upload_appender_file(group_name, local_filename, file_ext_name, meta_list); if (parts != null) { return parts[0] + SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + parts[1]; } else { return null; } }
Example #7
Source File: MonitorServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("unchecked") @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public List<Group> listGroups() throws IOException, MyException { List<Group> groups = new ArrayList<Group>(); Session session = getSession(); StringBuilder queryString = new StringBuilder( "from Group as g GROUP BY groupName"); Query query = session.createQuery(queryString.toString()); groups = query.list(); return groups; }
Example #8
Source File: UserServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@Override @Transactional(propagation = Propagation.REQUIRED) public List<User> userlist(String username) throws IOException, MyException { //To change body of implemented methods use File | Settings | File Templates. List<User> users = new ArrayList<User>(); Session session = getSession(); StringBuilder queryString = new StringBuilder("from User as u "); if(username!=null&&username!=""){ queryString.append("where u.name like '%"+username+"%'"); } Query query = session.createQuery(queryString.toString()); users = query.list(); return users; }
Example #9
Source File: StorageClient.java From mumu with Apache License 2.0 | 5 votes |
/** * download file from storage server * @param group_name the group name of storage server * @param remote_filename filename on storage server * @param callback call callback.recv() when data arrive * @return 0 success, return none zero errno if fail */ public int download_file(String group_name, String remote_filename, DownloadCallback callback) throws IOException, MyException { final long file_offset = 0; final long download_bytes = 0; return this.download_file(group_name, remote_filename, file_offset, download_bytes, callback); }
Example #10
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * upload file to storage server (by file buff) * * @param file_buff file content/buff * @param file_ext_name file ext name, do not include dot(.) * @param meta_list meta info array * @return file id(including group name and filename) if success, <br> * return null if fail */ public String upload_file1(byte[] file_buff, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException { String parts[] = this.upload_file(file_buff, file_ext_name, meta_list); if (parts != null) { return parts[0] + SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + parts[1]; } else { return null; } }
Example #11
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * append file to storage server (by file buff) * * @param appender_file_id the appender file id * @param file_buff file content/buffer * @param offset start offset of the buffer * @param length the length of the buffer to append * @return 0 for success, != 0 for error (error no) */ public int append_file1(String appender_file_id, byte[] file_buff, int offset, int length) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(appender_file_id, parts); if (this.errno != 0) { return this.errno; } return this.append_file(parts[0], parts[1], file_buff, offset, length); }
Example #12
Source File: JobServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
public void warningOffline(Storage storage) throws IOException, MyException { List<WarningData> warningDatas = warningService.findByIp(storage.getIpAddr()); boolean res = false; StringBuffer stringBuffer = new StringBuffer("异常服务器 :" + storage.getIpAddr() + "</br>"); if (storage.getCurStatus().equals("OFFLINE")) { stringBuffer.append("服务器停止工作"); if (datemap.containsKey(storage.getIpAddr())) { Date offdate = datemap.get(storage.getIpAddr()); Date now = new Date(); long temp = now.getTime() - offdate.getTime(); if (temp >= 1000 * 60 * 60) { datemap.put(storage.getIpAddr(), new Date()); res = true; } } else { datemap.put(storage.getIpAddr(), new Date()); res = true; } } else { if (datemap.containsKey(storage.getIpAddr())) { datemap.remove(storage.getIpAddr()); } } if (res) { BuildMail buildMail = new BuildMail(); List<WarningUser> warningUser = new ArrayList<WarningUser>(); warningUser = warningService.findWarUser(); for (WarningUser wu : warningUser) { buildMail.sendWarning("VivaMe维我", wu.getEmail(), "dfs预警报告", stringBuffer.toString()); } } }
Example #13
Source File: WarningServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@Override @Transactional(propagation = Propagation.REQUIRED) public void updateWarning(WarningData wd) throws IOException, MyException { //To change body of implemented methods use File | Settings | File Templates. Session session = getSession(); session.saveOrUpdate(wd); }
Example #14
Source File: JobServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@Override @Scheduled(cron = "0 0/1 * * * ?") @Transactional(propagation = Propagation.REQUIRED) public void updateGroupByMinute() throws IOException, MyException, JSchException { logger.info("group minute data upate begin..."); List<Group> groups = getGroupInfoByMinute(); Session session = getSession(); for (Group group : groups) { session.save(group); } logger.info("group minute data upated end"); }
Example #15
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * get file info decoded from filename * * @param file_id the file id(including group name and filename) * @return FileInfo object for success, return null for fail */ public FileInfo get_file_info1(String file_id) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(file_id, parts); if (this.errno != 0) { return null; } return this.get_file_info(parts[0], parts[1]); }
Example #16
Source File: StorageClient.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * check storage socket, if null create a new connection * * @param group_name the group name of storage server * @param remote_filename filename on storage server * @return true if create a new connection */ protected boolean newReadableStorageConnection(String group_name, String remote_filename) throws IOException, MyException { if (this.storageServer != null) { return false; } else { TrackerClient tracker = new TrackerClient(); this.storageServer = tracker.getFetchStorage(this.trackerServer, group_name, remote_filename); if (this.storageServer == null) { throw new MyException("getStoreStorage fail, errno code: " + tracker.getErrorCode()); } return true; } }
Example #17
Source File: StorageClient.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * check storage socket, if null create a new connection * * @param group_name the group name of storage server * @param remote_filename filename on storage server * @return true if create a new connection */ protected boolean newUpdatableStorageConnection(String group_name, String remote_filename) throws IOException, MyException { if (this.storageServer != null) { return false; } else { TrackerClient tracker = new TrackerClient(); this.storageServer = tracker.getUpdateStorage(this.trackerServer, group_name, remote_filename); if (this.storageServer == null) { throw new MyException("getStoreStorage fail, errno code: " + tracker.getErrorCode()); } return true; } }
Example #18
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * regenerate filename for appender file * * @param appender_file_id the appender file id * @return the regenerated file id, return null if fail */ public String regenerate_appender_filename1(String appender_file_id) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(appender_file_id, parts); if (this.errno != 0) { return null; } String[] new_parts = this.regenerate_appender_filename(parts[0], parts[1]); if (new_parts != null) { return new_parts[0] + SPLIT_GROUP_NAME_AND_FILENAME_SEPERATOR + new_parts[1]; } else { return null; } }
Example #19
Source File: StorageClient.java From mumu with Apache License 2.0 | 5 votes |
/** * append file to storage server (by file name) * @param group_name the group name of appender file * @param appender_filename the appender filename * @param local_filename local filename to append * @return 0 for success, != 0 for error (error no) */ public int append_file(String group_name, String appender_filename, String local_filename) throws IOException, MyException { File f = new File(local_filename); FileInputStream fis = new FileInputStream(f); try { return this.do_append_file(group_name, appender_filename, f.length(), new UploadStream(fis, f.length())); } finally { fis.close(); } }
Example #20
Source File: MonitorAction.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@RequestMapping("/capacity") public ModelAndView capacity() throws IOException, MyException,JSchException { ModelAndView mv = new ModelAndView("monitor/capacity.jsp"); mv.addObject("groupInfo", monitorService.listGroupInfo()); return mv; }
Example #21
Source File: StorageClient1.java From mumu with Apache License 2.0 | 5 votes |
/** * get all metadata items from storage server * @param file_id the file id(including group name and filename) * @return meta info array, return null if fail */ public NameValuePair[] get_metadata1(String file_id)throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(file_id, parts); if (this.errno != 0) { return null; } return this.get_metadata(parts[0], parts[1]); }
Example #22
Source File: StorageClient1.java From mumu with Apache License 2.0 | 5 votes |
/** * get file info from storage server * @param file_id the file id(including group name and filename) * @return FileInfo object for success, return null for fail */ public FileInfo query_file_info1(String file_id) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(file_id, parts); if (this.errno != 0) { return null; } return this.query_file_info(parts[0], parts[1]); }
Example #23
Source File: ProtoCommon.java From mumu with Apache License 2.0 | 5 votes |
/** * get token for file URL * @param remote_filename the filename return by FastDFS server * @param ts unix timestamp, unit: second * @param secret_key the secret key * @return token string */ public static String getToken(String remote_filename, int ts, String secret_key) throws UnsupportedEncodingException, NoSuchAlgorithmException, MyException { byte[] bsFilename = remote_filename.getBytes(ClientGlobal.g_charset); byte[] bsKey = secret_key.getBytes(ClientGlobal.g_charset); byte[] bsTimestamp = (new Integer(ts)).toString().getBytes(ClientGlobal.g_charset); byte[] buff = new byte[bsFilename.length + bsKey.length + bsTimestamp.length]; System.arraycopy(bsFilename, 0, buff, 0, bsFilename.length); System.arraycopy(bsKey, 0, buff, bsFilename.length, bsKey.length); System.arraycopy(bsTimestamp, 0, buff, bsFilename.length + bsKey.length, bsTimestamp.length); return md5(buff); }
Example #24
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * download file from storage server * * @param file_id the file id(including group name and filename) * @param file_offset the start offset of the file * @param download_bytes download bytes, 0 for remain bytes from offset * @return file content/buff, return null if fail */ public byte[] download_file1(String file_id, long file_offset, long download_bytes) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(file_id, parts); if (this.errno != 0) { return null; } return this.download_file(parts[0], parts[1], file_offset, download_bytes); }
Example #25
Source File: StorageClient.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * append file to storage server (by file name) * * @param group_name the group name of appender file * @param appender_filename the appender filename * @param local_filename local filename to append * @return 0 for success, != 0 for error (error no) */ public int append_file(String group_name, String appender_filename, String local_filename) throws IOException, MyException { File f = new File(local_filename); FileInputStream fis = new FileInputStream(f); try { return this.do_append_file(group_name, appender_filename, f.length(), new UploadStream(fis, f.length())); } finally { fis.close(); } }
Example #26
Source File: MonitorServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@Override @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public StorageHour getStorageByIp(String ip) throws IOException, MyException { System.out.println(ip); StorageHour storages = new StorageHour(); Session session = getSession(); String str = "from StorageHour as s where s.ipAddr='" + ip + "' order by s.created desc"; Query query = session.createQuery(str); query.setFirstResult(1); query.setMaxResults(1); storages = (StorageHour) query.list().get(0); return storages; }
Example #27
Source File: MonitorAction.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
@ResponseBody @RequestMapping("/fileCountStorage") public List<Line> fileCountStorage(String ip, String startTime, String endTime) throws IOException, MyException { List<Line> result = new ArrayList<Line>(); result = monitorService.getListFileCountStorage(ip, startTime, endTime); return result; }
Example #28
Source File: JobServiceImpl.java From fastdfs-zyc with GNU General Public License v2.0 | 5 votes |
private void warning(Storage storage) throws IOException, MyException { List<WarningData> warningDatas = warningService.findByIp(storage.getIpAddr()); StringBuffer stringBuffer = new StringBuffer("异常服务器:" + storage.getIpAddr() + "</br>"); if (!warningDatas.isEmpty()) { float wdCup = Float.parseFloat(warningDatas.get(0).getWdCpu()); float wdMem = warningDatas.get(0).getWdMem(); long wdFreeMB = warningDatas.get(0).getWdFreeMB(); boolean res = true; if (Float.parseFloat(storage.getCpu()) > wdCup) { stringBuffer.append("cpu使用率当前值为: " + storage.getCpu() + "% 大于预警值:" + wdCup + "%</br>"); res = false; } if (storage.getMem() > wdMem) { stringBuffer.append("内存使用率当前值为: " + storage.getMem() + "% 大于预警值:" + wdMem + "%</br>"); res = false; } if (storage.getFreeMB() < wdFreeMB) { stringBuffer.append("可用空间当前值为: " + storage.getFreeMB() + "MB 小于预警值:" + wdFreeMB + "MB</br>"); res = false; } if (!res) { BuildMail buildMail = new BuildMail(); List<WarningUser> warningUser = new ArrayList<WarningUser>(); warningUser = warningService.findWarUser(); for (WarningUser wu : warningUser) { buildMail.sendWarning("VivaMe维我", wu.getEmail(), "dfs预警报告", stringBuffer.toString()); } } } }
Example #29
Source File: StorageClient1.java From fastdfs-client-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * download file from storage server * * @param file_id the file id(including group name and filename) * @param file_offset the start offset of the file * @param download_bytes download bytes, 0 for remain bytes from offset * @param callback the callback object, will call callback.recv() when data arrive * @return 0 success, return none zero errno if fail */ public int download_file1(String file_id, long file_offset, long download_bytes, DownloadCallback callback) throws IOException, MyException { String[] parts = new String[2]; this.errno = this.split_file_id(file_id, parts); if (this.errno != 0) { return this.errno; } return this.download_file(parts[0], parts[1], file_offset, download_bytes, callback); }
Example #30
Source File: StorageClient.java From mumu with Apache License 2.0 | 5 votes |
/** * upload file to storage server (by file name, slave file mode) * @param group_name the group name of master file * @param master_filename the master file name to generate the slave file * @param prefix_name the prefix name to generate the slave file * @param local_filename local filename to upload * @param file_ext_name file ext name, do not include dot(.), null to extract ext name from the local filename * @param meta_list meta info array * @return 2 elements string array if success:<br> * <ul><li>results[0]: the group name to store the file </li></ul> * <ul><li>results[1]: the new created filename</li></ul> * return null if fail */ public String[] upload_file(String group_name, String master_filename, String prefix_name, String local_filename, String file_ext_name, NameValuePair[] meta_list) throws IOException, MyException { if ((group_name == null || group_name.length() == 0) || (master_filename == null || master_filename.length() == 0) || (prefix_name == null)) { throw new MyException("invalid arguement"); } File f = new File(local_filename); FileInputStream fis = new FileInputStream(f); if (file_ext_name == null) { int nPos = local_filename.lastIndexOf('.'); if (nPos > 0 && local_filename.length() - nPos <= ProtoCommon.FDFS_FILE_EXT_NAME_MAX_LEN + 1) { file_ext_name = local_filename.substring(nPos+1); } } try { return this.do_upload_file(ProtoCommon.STORAGE_PROTO_CMD_UPLOAD_SLAVE_FILE, group_name, master_filename, prefix_name, file_ext_name, f.length(), new UploadStream(fis, f.length()), meta_list); } finally { fis.close(); } }