jackrabbit-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ravindar.singh" <ravindar.si...@qicgroup.com.qa>
Subject Re: Slowness while multiple uploads
Date Mon, 09 Jan 2017 18:03:09 GMT
Please check the below code. correct me if any thing wrong.

After restarting the server it is quit normal then 1 day later it is taking
2 min to upload the file.

private void contentStroe(UploadParameters repContent, List<ProjectProp>
configParams, 
            String workspace, String table) throws Exception{
        Session repSession = null;
        Repository repository = null;
        try{
            String path = repContent.getModule();                        
            Map<String, Object> nodeProps = repContent.getParams();
            for(ProjectProp prop: configParams){
                if("1".equals(prop.getMppFolderYn())){
                    Object value =
nodeProps.get(prop.getMppParameterName());
                    if(value!=null)
                        path += "/" + value.toString();
                }
            }
            logger.info("Path => "+path);
            Calendar cal = Calendar.getInstance();
            DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd
HH:mm:ss");
            repository = getRepository();
            repSession = repository.login(new SimpleCredentials("admin",
"admin".toCharArray()), workspace);
            Node folderNode = repSession.getRootNode();
            String[] docPath = path.split("/");
            long docSize = 0;
            String docExtn = "", docVersion = "";
            for(String nodes : docPath){
                if (folderNode.hasNode(nodes)) {
                    folderNode = folderNode.getNode(nodes);
                } else {
                    boolean versioned = isVersioned(folderNode);
                    if(versioned)
                        folderNode.checkout();
                    Node subFolderNode = folderNode.addNode(nodes);
                    subFolderNode.addMixin("mix:referenceable");
                    subFolderNode.addMixin("mix:versionable");
                    subFolderNode.setProperty("Created",
dateFormat.format(cal.getTime()));
                    subFolderNode.setProperty("CreatedBy",
repContent.getUpdUser());
                    repSession.save();
                    if(versioned)
                        folderNode.checkin();
                    subFolderNode.checkin();
                    folderNode = folderNode.getNode(nodes);
                }
            }

            if(repContent.getUpdFile()!=null){
                String name = repContent.getUpdFileName();
                docExtn = name.substring(name.lastIndexOf(".")+1);
            }
            repContent.setDocName(repContent.getDocName()+"."+docExtn);
            logger.info("File Store
Path=>"+path+"/"+repContent.getDocName());
            if (folderNode.hasNode(repContent.getDocName())) {
                boolean versioned = isVersioned(folderNode);
                if(versioned)
                    folderNode.checkout();
                Node fileNode = folderNode.getNode(repContent.getDocName());
                boolean fileversioned = isVersioned(fileNode);
                if(fileversioned)
                    fileNode.checkout();
                fileNode.setProperty("lastModified",
dateFormat.format(cal.getTime()));
                fileNode.setProperty("UpdateBy", repContent.getUpdUser());
                docSize = addRepoContents(repSession, fileNode, repContent,
configParams);
                repSession.save();
                if(versioned)
                    folderNode.checkin();
                if(fileversioned)
                    fileNode.checkin();
                VersionManager versionManager =
repSession.getWorkspace().getVersionManager();
                VersionHistory hist =
versionManager.getVersionHistory("/"+path+"/"+repContent.getDocName());
                for (VersionIterator it = hist.getAllVersions();
it.hasNext();) {
                    Version version = (Version) it.next();
                    logger.info("Version1 Name=>"+version.getName());
                    docVersion = version.getName();
                }
            } else {
                boolean versioned = isVersioned(folderNode);
                if(versioned)
                    folderNode.checkout();
                Node fileNode = folderNode.addNode(repContent.getDocName());
                fileNode.addMixin("mix:referenceable");
                fileNode.addMixin("mix:versionable");
                fileNode.setProperty("Created",
dateFormat.format(cal.getTime()));
                fileNode.setProperty("CreatedBy", repContent.getUpdUser());
                fileNode.setProperty("deleteOption", "Y");
                fileNode.setProperty("versioning", "Y");
                docSize = addRepoContents(repSession, fileNode, repContent,
configParams);
                repSession.save();
                if(versioned)
                    folderNode.checkin();
                fileNode.checkin();
                VersionManager versionManager =
repSession.getWorkspace().getVersionManager();
                VersionHistory hist =
versionManager.getVersionHistory("/"+path+"/"+repContent.getDocName());
                for (VersionIterator it = hist.getAllVersions();
it.hasNext();) {
                    Version version = (Version) it.next();
                    logger.info("Version Name=>"+version.getName());
                    docVersion = version.getName();
                }
            }
            repSession.save();
            dao.insertDocDetails(table, repContent, configParams,
docVersion, path, docSize, docExtn);
        } catch (Exception e) {
            throw e;
        } finally {
            if(repSession!=null){
                try{
                    repSession.save();
                }catch(Exception e){logger.error("Exception in Session Save
{}", e);}
                *repSession.logout();*
                repSession = null;
                repository = null;
            }
        }
    }
    
    private long addRepoContents(Session repSession, Node fileNode,
UploadParameters repContent, 
            List<ProjectProp> configParams) throws Exception{
        byte[] updFile = repContent.getUpdFileByte();
        long res = 0;
        if(updFile!=null){
            res = updFile.length;
            ByteArrayInputStream fileContentStream = new
ByteArrayInputStream(updFile);
            Binary fileContent =
repSession.getValueFactory().createBinary(fileContentStream);
            fileNode.setProperty("mimeType",
repContent.getUpdFileContentType());
            fileNode.setProperty("size", res);
            fileNode.setProperty("data", fileContent);
            fileContentStream.close();
            fileNode.setProperty("fileName", repContent.getUpdFileName());
            logger.info("File Name: "+repContent.getUpdFileName()+"; File
Size: "+res+"; File Content Type: "+repContent.getUpdFileContentType());
            
            fileNode.setProperty("Category", repContent.getCategory());
            fileNode.setProperty("DocCode", repContent.getDocCode());
            fileNode.setProperty("DocName", repContent.getDocName());
            fileNode.setProperty("DocRemarks", repContent.getRemarks());

            logger.info("Additional Params:");
            Map<String, Object> nodeProps = repContent.getParams();
            for (ProjectProp props : configParams) {
                Object value = nodeProps.get(props.getMppParameterName());
                logger.info("Name: "+props.getMppParameterName());
                logger.info("Type: "+props.getMppDataType());
                logger.info("Value: "+value);
                if("C".equals(props.getMppDataType())){
                    fileNode.setProperty(props.getMppParameterDesc(),
String.valueOf(value));
                } else if("N".equals(props.getMppDataType())) {
                    fileNode.setProperty(props.getMppParameterDesc(),
Long.valueOf(value==null?"0":value.toString()));
                } else if("D".equals(props.getMppDataType())) {
                    fileNode.setProperty(props.getMppParameterDesc(),
(Calendar)value);
                }
            }
        }
        return res;
    }



--
View this message in context: http://jackrabbit.510166.n4.nabble.com/Slowness-while-multiple-uploads-tp4666061p4666070.html
Sent from the Jackrabbit - Dev mailing list archive at Nabble.com.

Mime
View raw message