Source Code Cross Referenced for Database.java in  » Portal » Open-Portal » com » sun » portal » search » admin » mbeans » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Portal » Open Portal » com.sun.portal.search.admin.mbeans 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.sun.portal.search.admin.mbeans;
0002:
0003:        import java.io.*;
0004:        import java.util.*;
0005:        import java.util.logging.*;
0006:        import java.net.*;
0007:        import java.lang.*;
0008:        import java.text.*;
0009:
0010:        import javax.management.MBeanServer;
0011:        import javax.management.remote.JMXConnector;
0012:        import javax.management.MBeanServerConnection;
0013:        import javax.management.ObjectName;
0014:
0015:        import com.sun.portal.log.common.*;
0016:
0017:        import com.sun.portal.admin.server.PASModule;
0018:        import com.sun.portal.admin.server.AdminServerUtil;
0019:        import com.sun.portal.admin.server.mbeans.PSResource;
0020:        import com.sun.portal.admin.common.util.AdminUtil;
0021:        import com.sun.portal.admin.common.context.PortalDomainContext;
0022:        import com.sun.portal.admin.common.context.PSConfigContext;
0023:        import com.sun.portal.admin.common.PSMBeanException;
0024:        import com.sun.portal.log.common.PortalLogger;
0025:        import com.sun.portal.search.admin.CSConfig;
0026:        import com.sun.portal.search.soif.*;
0027:        import com.sun.portal.search.rdm.RDM;
0028:
0029:        import com.sun.portal.util.Platform;
0030:
0031:        public class Database extends PSResource implements  DatabaseMBean {
0032:
0033:            private ObjectName searchServerObjectName = null;
0034:            private ObjectName objectName = null;
0035:            private String host = null;
0036:
0037:            private String searchServerID = null;
0038:            private String searchServerRoot = null;
0039:
0040:            private ArrayList databases = null;
0041:            private String searchDatabaseDir = null;
0042:            private Date lastSearchConfigUpdated = null;
0043:            private Date lastDBUpdated = null;
0044:
0045:            private static Logger logger = PortalLogger
0046:                    .getLogger(Database.class);
0047:
0048:            public void init(PSConfigContext cc, PortalDomainContext pdc,
0049:                    List path) {
0050:                super .init(cc, pdc, path);
0051:
0052:                try {
0053:                    LinkedList ll = new LinkedList();
0054:                    ll.addFirst(path.get(2));
0055:                    ll.addFirst(path.get(1));
0056:                    searchServerObjectName = AdminUtil
0057:                            .getResourceMBeanObjectName(
0058:                                    AdminUtil.SEARCHSERVER_MBEAN_TYPE, ll);
0059:
0060:                    objectName = AdminUtil.getResourceMBeanObjectName(TYPE,
0061:                            path);
0062:                    host = pdc.getAttributeValue(TYPE, path, "Host");
0063:                } catch (Exception e) {
0064:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0065:                }
0066:
0067:                searchServerID = (String) path.get(1);
0068:
0069:                searchServerRoot = cc.getPSDataDir() + File.separator
0070:                        + "searchservers" + File.separator + searchServerID;
0071:
0072:                databases = new ArrayList();
0073:            }
0074:
0075:            /*
0076:             ** retrieveAll
0077:             **
0078:             ** Output:
0079:             **    data (ArrayList) - url (String)
0080:             */
0081:            public ArrayList retrieveAll() throws PSMBeanException,
0082:                    java.net.UnknownHostException {
0083:                if (!AdminUtil.isLocal(host)) {
0084:                    try {
0085:                        JMXConnector jmxc = AdminServerUtil
0086:                                .getJMXConnector(host);
0087:                        MBeanServerConnection msc = jmxc
0088:                                .getMBeanServerConnection();
0089:                        Object[] params = {};
0090:                        String[] signatures = {};
0091:                        ArrayList result = (ArrayList) msc.invoke(objectName,
0092:                                "retrieveAll", params, signatures);
0093:                        jmxc.close();
0094:                        return result;
0095:                    } catch (Exception e) {
0096:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0097:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0098:                                .toString(), e);
0099:                    }
0100:                } else {
0101:                    try {
0102:                        syncDatabase();
0103:                    } catch (Exception e) {
0104:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0105:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0106:                                .toString(), e);
0107:                    }
0108:
0109:                    ArrayList result = new ArrayList();
0110:                    for (int index = 0; index < databases.size(); index++) {
0111:                        SOIF s = (SOIF) databases.get(index);
0112:                        result.add(s.getURL());
0113:                    }
0114:                    return result;
0115:                }
0116:            }
0117:
0118:            /*
0119:             ** getAttributes
0120:             **
0121:             ** Output:
0122:             **    properties (Properties)
0123:             */
0124:            public Properties getAttributes(String name)
0125:                    throws PSMBeanException, java.net.UnknownHostException {
0126:                if (!AdminUtil.isLocal(host)) {
0127:                    try {
0128:                        JMXConnector jmxc = AdminServerUtil
0129:                                .getJMXConnector(host);
0130:                        MBeanServerConnection msc = jmxc
0131:                                .getMBeanServerConnection();
0132:                        Object[] params = { name };
0133:                        String[] signatures = { "java.lang.String" };
0134:                        Properties result = (Properties) msc.invoke(objectName,
0135:                                "getAttributes", params, signatures);
0136:                        jmxc.close();
0137:                        return result;
0138:                    } catch (Exception e) {
0139:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0140:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0141:                                .toString(), e);
0142:                    }
0143:                } else {
0144:                    if (name == null) {
0145:                        String message = "No database name specified";
0146:                        Object tokens[] = { message };
0147:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0148:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0149:                    }
0150:
0151:                    try {
0152:                        syncDatabase();
0153:                    } catch (Exception e) {
0154:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0155:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0156:                                .toString(), e);
0157:                    }
0158:
0159:                    Properties p = new Properties();
0160:
0161:                    for (int index = 0; index < databases.size(); index++) {
0162:                        SOIF s = (SOIF) databases.get(index);
0163:                        if (s.getURL().equals(name)) {
0164:                            String[] array = s.getAttributesArray();
0165:                            for (int i = 0; i < array.length; i++) {
0166:                                String key = array[i];
0167:                                String value = s.getValue(key);
0168:                                p.setProperty(key, (value != null) ? value
0169:                                        : null);
0170:                            }
0171:                        }
0172:                    }
0173:
0174:                    return p;
0175:                }
0176:            }
0177:
0178:            /*
0179:             ** setAttributes
0180:             */
0181:            public void setAttributes(String name, Properties attributes)
0182:                    throws PSMBeanException, java.net.UnknownHostException {
0183:                if (!AdminUtil.isLocal(host)) {
0184:                    try {
0185:                        JMXConnector jmxc = AdminServerUtil
0186:                                .getJMXConnector(host);
0187:                        MBeanServerConnection msc = jmxc
0188:                                .getMBeanServerConnection();
0189:                        Object[] params = { name, attributes };
0190:                        String[] signatures = { "java.lang.String",
0191:                                "java.util.Properties" };
0192:                        msc.invoke(objectName, "setAttributes", params,
0193:                                signatures);
0194:                        jmxc.close();
0195:                    } catch (Exception e) {
0196:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0197:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0198:                                .toString(), e);
0199:                    }
0200:                } else {
0201:                    if (name == null) {
0202:                        String message = "No database name specified";
0203:                        Object tokens[] = { message };
0204:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0205:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0206:                    }
0207:                    if (attributes == null) {
0208:                        String message = "No database attributes specified";
0209:                        Object tokens[] = { message };
0210:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0211:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0212:                    }
0213:
0214:                    try {
0215:                        syncDatabase();
0216:                    } catch (Exception e) {
0217:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0218:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0219:                                .toString(), e);
0220:                    }
0221:
0222:                    try {
0223:                        for (int index = 0; index < databases.size(); index++) {
0224:                            SOIF s = (SOIF) databases.get(index);
0225:
0226:                            if (s.getURL().equals(name)) {
0227:
0228:                                String[] array = s.getAttributesArray();
0229:                                for (int i = 0; i < array.length; i++) {
0230:                                    String key = array[i];
0231:                                    if (!attributes.containsKey(key)) {
0232:                                        s.remove(key);
0233:                                    }
0234:                                }
0235:
0236:                                Enumeration e = attributes.propertyNames();
0237:                                while (e.hasMoreElements()) {
0238:                                    String key = (String) e.nextElement();
0239:                                    String value = (String) attributes
0240:                                            .getProperty(key);
0241:                                    if (s.contains(key)) {
0242:                                        s.replace(key, value);
0243:                                    } else {
0244:                                        s.insert(key, value);
0245:                                    }
0246:                                }
0247:
0248:                                String fileName = searchServerRoot
0249:                                        + File.separator
0250:                                        + "tmp"
0251:                                        + File.separator
0252:                                        + "database."
0253:                                        + Long.toString(System
0254:                                                .currentTimeMillis());
0255:
0256:                                SOIFOutputStream os = new SOIFOutputStream(
0257:                                        fileName);
0258:                                os.write(s);
0259:                                os.close();
0260:
0261:                                Process p = execute("rdmgr -D -y root -q "
0262:                                        + fileName);
0263:                                p.waitFor();
0264:                                int exitValue = p.exitValue();
0265:                                if (exitValue != 0) {
0266:                                    String message = "Updating database description for "
0267:                                            + name
0268:                                            + " failed with "
0269:                                            + exitValue;
0270:                                    Object tokens[] = { message };
0271:                                    logger.log(Level.SEVERE,
0272:                                            "PSSH_CSPSAMB0002", tokens);
0273:                                    throw new PSMBeanException(
0274:                                            "PSALI_CSPACCSH0001");
0275:                                }
0276:                            }
0277:                        }
0278:                    } catch (Exception e) {
0279:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0280:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0281:                                .toString(), e);
0282:                    }
0283:                }
0284:            }
0285:
0286:            /*
0287:             ** deleteAttributes
0288:             */
0289:            public void deleteAttributes(String name, List attributes)
0290:                    throws PSMBeanException, java.net.UnknownHostException {
0291:                if (!AdminUtil.isLocal(host)) {
0292:                    try {
0293:                        JMXConnector jmxc = AdminServerUtil
0294:                                .getJMXConnector(host);
0295:                        MBeanServerConnection msc = jmxc
0296:                                .getMBeanServerConnection();
0297:                        Object[] params = { name, attributes };
0298:                        String[] signatures = { "java.lang.String",
0299:                                "java.util.List" };
0300:                        msc.invoke(objectName, "deleteAttributes", params,
0301:                                signatures);
0302:                        jmxc.close();
0303:                    } catch (Exception e) {
0304:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0305:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0306:                                .toString(), e);
0307:                    }
0308:                } else {
0309:                    if (name == null) {
0310:                        String message = "No database name specified";
0311:                        Object tokens[] = { message };
0312:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0313:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0314:                    }
0315:                    if (attributes == null) {
0316:                        String message = "No database attributes specified";
0317:                        Object tokens[] = { message };
0318:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0319:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0320:                    }
0321:
0322:                    try {
0323:                        syncDatabase();
0324:                    } catch (Exception e) {
0325:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0326:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0327:                                .toString(), e);
0328:                    }
0329:
0330:                    try {
0331:                        for (int index1 = 0; index1 < databases.size(); index1++) {
0332:                            SOIF s = (SOIF) databases.get(index1);
0333:                            if (s.getURL().equals(name)) {
0334:                                for (int index2 = 0; index2 < attributes.size(); index2++) {
0335:                                    String key = (String) attributes
0336:                                            .get(index2);
0337:                                    if (s.contains(key)) {
0338:                                        s.remove(key);
0339:                                    }
0340:                                }
0341:
0342:                                String fileName = searchServerRoot
0343:                                        + File.separator
0344:                                        + "tmp"
0345:                                        + File.separator
0346:                                        + "database."
0347:                                        + Long.toString(System
0348:                                                .currentTimeMillis());
0349:
0350:                                SOIFOutputStream os = new SOIFOutputStream(
0351:                                        fileName);
0352:                                os.write(s);
0353:                                os.close();
0354:
0355:                                Process p = execute("rdmgr -D -y root -q "
0356:                                        + fileName);
0357:                                p.waitFor();
0358:                                int exitValue = p.exitValue();
0359:                                if (exitValue != 0) {
0360:                                    String message = "Updating database description for "
0361:                                            + name
0362:                                            + " failed with "
0363:                                            + exitValue;
0364:                                    Object tokens[] = { message };
0365:                                    logger.log(Level.SEVERE,
0366:                                            "PSSH_CSPSAMB0002", tokens);
0367:                                    throw new PSMBeanException(
0368:                                            "PSALI_CSPACCSH0001");
0369:                                }
0370:                            }
0371:                        }
0372:                    } catch (Exception e) {
0373:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0374:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0375:                                .toString(), e);
0376:                    }
0377:                }
0378:            }
0379:
0380:            /*
0381:             ** create
0382:             */
0383:            public void create(String name, Properties attributes)
0384:                    throws PSMBeanException, java.net.UnknownHostException {
0385:                if (!AdminUtil.isLocal(host)) {
0386:                    try {
0387:                        JMXConnector jmxc = AdminServerUtil
0388:                                .getJMXConnector(host);
0389:                        MBeanServerConnection msc = jmxc
0390:                                .getMBeanServerConnection();
0391:                        Object[] params = { name, attributes };
0392:                        String[] signatures = { "java.lang.String",
0393:                                "java.util.Properties" };
0394:                        msc.invoke(objectName, "create", params, signatures);
0395:                        jmxc.close();
0396:                    } catch (Exception e) {
0397:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0398:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0399:                                .toString(), e);
0400:                    }
0401:                } else {
0402:                    if (name == null) {
0403:                        String message = "No database name specified";
0404:                        Object tokens[] = { message };
0405:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0406:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0407:                    }
0408:                    if (attributes == null) {
0409:                        attributes = new Properties();
0410:                    }
0411:
0412:                    if (!validateName(name)) {
0413:                        String message = "Invalid database name - " + name;
0414:                        Object tokens[] = { message };
0415:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0416:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0417:                    }
0418:
0419:                    try {
0420:                        syncDatabase();
0421:                    } catch (Exception e) {
0422:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0423:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0424:                                .toString(), e);
0425:                    }
0426:
0427:                    for (int index = 0; index < databases.size(); index++) {
0428:                        SOIF s = (SOIF) databases.get(index);
0429:                        if (s.getURL().compareToIgnoreCase(name) == 0) {
0430:                            String message = "Database already exists - "
0431:                                    + name;
0432:                            Object tokens[] = { message };
0433:                            logger
0434:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0435:                                            tokens);
0436:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0437:                        }
0438:                    }
0439:
0440:                    try {
0441:                        Process p = execute("rdmgr -y " + name + " -n");
0442:                        p.waitFor();
0443:                        int exitValue = p.exitValue();
0444:                        if (exitValue != 0) {
0445:                            String message = "Creating database " + name
0446:                                    + " failed with " + exitValue;
0447:                            Object tokens[] = { message };
0448:                            logger
0449:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0450:                                            tokens);
0451:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0452:                        }
0453:
0454:                        SOIF s = new SOIF("Database", name);
0455:                        Enumeration e = attributes.propertyNames();
0456:                        while (e.hasMoreElements()) {
0457:                            String key = (String) e.nextElement();
0458:                            String value = (String) attributes.getProperty(key);
0459:                            if (s.contains(key)) {
0460:                                s.replace(key, value);
0461:                            } else {
0462:                                s.insert(key, value);
0463:                            }
0464:                        }
0465:
0466:                        String fileName = searchServerRoot + File.separator
0467:                                + "tmp" + File.separator + "database."
0468:                                + Long.toString(System.currentTimeMillis());
0469:
0470:                        SOIFOutputStream os = new SOIFOutputStream(fileName);
0471:                        os.write(s);
0472:                        os.close();
0473:
0474:                        p = execute("rdmgr -D -y root -m -q " + fileName);
0475:                        p.waitFor();
0476:                        exitValue = p.exitValue();
0477:                        if (exitValue != 0) {
0478:                            String message = "Creating database " + name
0479:                                    + " failed with " + exitValue;
0480:                            Object tokens[] = { message };
0481:                            logger
0482:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0483:                                            tokens);
0484:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0485:                        }
0486:                    } catch (Exception e) {
0487:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0488:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0489:                                .toString(), e);
0490:                    }
0491:                }
0492:            }
0493:
0494:            /*
0495:             ** reindex
0496:             */
0497:            public void reindex(String name) throws PSMBeanException,
0498:                    java.net.UnknownHostException {
0499:                if (!AdminUtil.isLocal(host)) {
0500:                    try {
0501:                        JMXConnector jmxc = AdminServerUtil
0502:                                .getJMXConnector(host);
0503:                        MBeanServerConnection msc = jmxc
0504:                                .getMBeanServerConnection();
0505:                        Object[] params = { name };
0506:                        String[] signatures = { "java.lang.String" };
0507:                        msc.invoke(objectName, "reindex", params, signatures);
0508:                        jmxc.close();
0509:                    } catch (Exception e) {
0510:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0511:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0512:                                .toString(), e);
0513:                    }
0514:                } else {
0515:                    if (name == null) {
0516:                        String message = "No database name specified";
0517:                        Object tokens[] = { message };
0518:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0519:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0520:                    }
0521:
0522:                    try {
0523:                        Process p = execute("rdmgr -I -p stdout -y " + name);
0524:                        p.waitFor();
0525:                        int exitValue = p.exitValue();
0526:                        if (exitValue != 0) {
0527:                            String message = "Reindexing database " + name
0528:                                    + " failed with " + exitValue;
0529:                            Object tokens[] = { message };
0530:                            logger
0531:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0532:                                            tokens);
0533:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0534:                        }
0535:                    } catch (Exception e) {
0536:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0537:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0538:                                .toString(), e);
0539:                    }
0540:                }
0541:            }
0542:
0543:            /*
0544:             ** purge
0545:             */
0546:            public void purge(String name) throws PSMBeanException,
0547:                    java.net.UnknownHostException {
0548:                if (!AdminUtil.isLocal(host)) {
0549:                    try {
0550:                        JMXConnector jmxc = AdminServerUtil
0551:                                .getJMXConnector(host);
0552:                        MBeanServerConnection msc = jmxc
0553:                                .getMBeanServerConnection();
0554:                        Object[] params = { name };
0555:                        String[] signatures = { "java.lang.String" };
0556:                        msc.invoke(objectName, "purge", params, signatures);
0557:                        jmxc.close();
0558:                    } catch (Exception e) {
0559:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0560:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0561:                                .toString(), e);
0562:                    }
0563:                } else {
0564:                    if (name == null) {
0565:                        String message = "No database name specified";
0566:                        Object tokens[] = { message };
0567:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0568:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0569:                    }
0570:
0571:                    try {
0572:                        Process p = execute("rdmgr -X -p stdout -y " + name);
0573:                        p.waitFor();
0574:                        int exitValue = p.exitValue();
0575:                        if (exitValue != 0) {
0576:                            String message = "Purging database " + name
0577:                                    + " failed with " + exitValue;
0578:                            Object tokens[] = { message };
0579:                            logger
0580:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0581:                                            tokens);
0582:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0583:                        }
0584:                    } catch (Exception e) {
0585:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0586:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0587:                                .toString(), e);
0588:                    }
0589:                }
0590:            }
0591:
0592:            /*
0593:             ** expire
0594:             */
0595:            public void expire(String name) throws PSMBeanException,
0596:                    java.net.UnknownHostException {
0597:                if (!AdminUtil.isLocal(host)) {
0598:                    try {
0599:                        JMXConnector jmxc = AdminServerUtil
0600:                                .getJMXConnector(host);
0601:                        MBeanServerConnection msc = jmxc
0602:                                .getMBeanServerConnection();
0603:                        Object[] params = { name };
0604:                        String[] signatures = { "java.lang.String" };
0605:                        msc.invoke(objectName, "expire", params, signatures);
0606:                        jmxc.close();
0607:                    } catch (Exception e) {
0608:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0609:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0610:                                .toString(), e);
0611:                    }
0612:                } else {
0613:                    if (name == null) {
0614:                        String message = "No database name specified";
0615:                        Object tokens[] = { message };
0616:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0617:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0618:                    }
0619:
0620:                    try {
0621:                        Process p = execute("rdmgr -E -p stdout -y " + name);
0622:                        p.waitFor();
0623:                        int exitValue = p.exitValue();
0624:                        if (exitValue != 0) {
0625:                            String message = "Expiring database " + name
0626:                                    + " failed with " + exitValue;
0627:                            Object tokens[] = { message };
0628:                            logger
0629:                                    .log(Level.SEVERE, "PSSH_CSPSAMB0002",
0630:                                            tokens);
0631:                            throw new PSMBeanException("PSALI_CSPACCSH0001");
0632:                        }
0633:                    } catch (Exception e) {
0634:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0635:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0636:                                .toString(), e);
0637:                    }
0638:                }
0639:            }
0640:
0641:            /*
0642:             ** getStatistics
0643:             **
0644:             ** Output:
0645:             **    data (ArrayList) - date (Date)
0646:             **			     protocols (HashTable) - protocol, count 1
0647:             **						     ...
0648:             **						     protocol, count N
0649:             **			     servers (HashTable) - server, count 1
0650:             **						   ...
0651:             **						   server, count N
0652:             */
0653:            public ArrayList getStatistics(String name, Boolean refresh)
0654:                    throws PSMBeanException, java.net.UnknownHostException {
0655:                if (!AdminUtil.isLocal(host)) {
0656:                    try {
0657:                        JMXConnector jmxc = AdminServerUtil
0658:                                .getJMXConnector(host);
0659:                        MBeanServerConnection msc = jmxc
0660:                                .getMBeanServerConnection();
0661:                        Object[] params = { name, refresh };
0662:                        String[] signatures = { "java.lang.String",
0663:                                "java.lang.Boolean" };
0664:                        ArrayList result = (ArrayList) msc.invoke(objectName,
0665:                                "getStatistics", params, signatures);
0666:                        jmxc.close();
0667:                        return result;
0668:                    } catch (Exception e) {
0669:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0670:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0671:                                .toString(), e);
0672:                    }
0673:                } else {
0674:                    if (name == null) {
0675:                        String message = "No database name specified";
0676:                        Object tokens[] = { message };
0677:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0678:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0679:                    }
0680:                    if (refresh == null) {
0681:                        refresh = new Boolean(false);
0682:                    }
0683:
0684:                    Hashtable protocols = new Hashtable();
0685:                    protocols.clear();
0686:
0687:                    Hashtable servers = new Hashtable();
0688:                    servers.clear();
0689:
0690:                    Date date = null;
0691:
0692:                    if (refresh.booleanValue()) {
0693:                        try {
0694:                            date = statisticsFromDatabase(name, protocols,
0695:                                    servers);
0696:                            saveStatistics(name, protocols, servers, date);
0697:                        } catch (Exception e) {
0698:                            logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0699:                            throw new PSMBeanException("PSALI_CSPACCSH0001", e
0700:                                    .toString(), e);
0701:                        }
0702:                    } else {
0703:                        try {
0704:                            date = statisticsFromFile(name, protocols, servers);
0705:                        } catch (Exception e1) {
0706:                            try {
0707:                                date = statisticsFromDatabase(name, protocols,
0708:                                        servers);
0709:                                saveStatistics(name, protocols, servers, date);
0710:                            } catch (Exception e2) {
0711:                                logger
0712:                                        .log(Level.SEVERE, "PSSH_CSPSAMB0003",
0713:                                                e2);
0714:                                throw new PSMBeanException(
0715:                                        "PSALI_CSPACCSH0001", e2.toString(), e2);
0716:                            }
0717:                        }
0718:                    }
0719:
0720:                    ArrayList result = new ArrayList();
0721:                    result.add(0, date);
0722:                    result.add(1, protocols);
0723:                    result.add(2, servers);
0724:                    return result;
0725:                }
0726:            }
0727:
0728:            /*
0729:             ** isStatisticsOld
0730:             **
0731:             ** Output:
0732:             **    state (Boolean)
0733:             */
0734:            public Boolean isStatisticsOld(String name)
0735:                    throws PSMBeanException, java.net.UnknownHostException {
0736:                if (!AdminUtil.isLocal(host)) {
0737:                    try {
0738:                        JMXConnector jmxc = AdminServerUtil
0739:                                .getJMXConnector(host);
0740:                        MBeanServerConnection msc = jmxc
0741:                                .getMBeanServerConnection();
0742:                        Object[] params = { name };
0743:                        String[] signatures = { "java.lang.String" };
0744:                        Boolean result = (Boolean) msc.invoke(objectName,
0745:                                "isStatisticsOld", params, signatures);
0746:                        jmxc.close();
0747:                        return result;
0748:                    } catch (Exception e) {
0749:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0750:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0751:                                .toString(), e);
0752:                    }
0753:                } else {
0754:                    if (name == null) {
0755:                        String message = "No database name specified";
0756:                        Object tokens[] = { message };
0757:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", tokens);
0758:                        throw new PSMBeanException("PSALI_CSPACCSH0001");
0759:                    }
0760:
0761:                    try {
0762:                        syncDatabase();
0763:                        for (int index = 0; index < databases.size(); index++) {
0764:                            SOIF s = (SOIF) databases.get(index);
0765:                            if (s.getURL().compareToIgnoreCase(name) == 0) {
0766:                                String lastModified = s
0767:                                        .getValue("DbStat-LastModified");
0768:                                if (lastModified == null) {
0769:                                    return new Boolean(false);
0770:                                } else {
0771:                                    SimpleDateFormat sdf = new SimpleDateFormat(
0772:                                            "EEE, d MMM yyyy HH:mm:ss z");
0773:                                    sdf.setLenient(true);
0774:                                    Date d = sdf.parse(lastModified);
0775:
0776:                                    File f = new File(searchServerRoot
0777:                                            + File.separator + "db"
0778:                                            + File.separator + name
0779:                                            + File.separator + "AL");
0780:                                    if (f.exists()) {
0781:                                        if (d
0782:                                                .before(new Date(f
0783:                                                        .lastModified()))) {
0784:                                            return new Boolean(true);
0785:                                        } else {
0786:                                            return new Boolean(false);
0787:                                        }
0788:                                    } else {
0789:                                        return new Boolean(true);
0790:                                    }
0791:                                }
0792:                            }
0793:                        }
0794:                        return new Boolean(true);
0795:                    } catch (Exception e) {
0796:                        logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
0797:                        throw new PSMBeanException("PSALI_CSPACCSH0001", e
0798:                                .toString(), e);
0799:                    }
0800:                }
0801:            }
0802:
0803:            private Date statisticsFromFile(String name, Hashtable protocols,
0804:                    Hashtable servers) throws Exception {
0805:                syncDatabase();
0806:                for (int index = 0; index < databases.size(); index++) {
0807:                    SOIF s = (SOIF) databases.get(index);
0808:                    if (s.getURL().compareToIgnoreCase(name) == 0) {
0809:                        int count = Integer.parseInt(s
0810:                                .getValue("DbStat-NbServer"));
0811:                        for (int i = 0; i < count; i++) {
0812:                            servers.put(s.getValue("DbStat-Href", i), s
0813:                                    .getValue("DbStat-Href-count", i));
0814:                        }
0815:
0816:                        count = Integer.parseInt(s
0817:                                .getValue("DbStat-NbProtocol"));
0818:                        for (int i = 0; i < count; i++) {
0819:                            protocols.put(s.getValue("DbStat-Protocol", i), s
0820:                                    .getValue("DbStat-Protocol-count", i));
0821:                        }
0822:
0823:                        SimpleDateFormat sdf = new SimpleDateFormat(
0824:                                "EEE, d MMM yyyy HH:mm:ss z");
0825:                        sdf.setLenient(true);
0826:                        return sdf.parse(s.getValue("DbStat-LastModified"));
0827:                    }
0828:                }
0829:
0830:                return new Date();
0831:            }
0832:
0833:            private Date statisticsFromDatabase(String name,
0834:                    Hashtable protocols, Hashtable servers) throws Exception {
0835:                Process p = execute("rdmgr -L -a url -y " + name);
0836:                BufferedReader br = new BufferedReader(new InputStreamReader(p
0837:                        .getInputStream()));
0838:                String line;
0839:                while ((line = br.readLine()) != null) {
0840:                    URL url = null;
0841:                    try {
0842:                        url = new URL(line);
0843:                    } catch (MalformedURLException murle) {
0844:                        url = null;
0845:                    }
0846:                    if (url != null) {
0847:                        String protocol = url.getProtocol();
0848:                        if (protocols.containsKey(protocol)) {
0849:                            int count = Integer.parseInt((String) protocols
0850:                                    .get(protocol));
0851:                            protocols.remove(protocol);
0852:                            protocols
0853:                                    .put(protocol, Integer.toString(count + 1));
0854:                        } else {
0855:                            protocols.put(protocol, "1");
0856:                        }
0857:
0858:                        String server = protocol + "://" + url.getHost() + ":"
0859:                                + Integer.toString(url.getPort()) + "/";
0860:                        if (servers.containsKey(server)) {
0861:                            int count = Integer.parseInt((String) servers
0862:                                    .get(server));
0863:                            servers.remove(server);
0864:                            servers.put(server, Integer.toString(count + 1));
0865:                        } else {
0866:                            servers.put(server, "1");
0867:                        }
0868:                    } else if (line != null) {
0869:                        if (line.startsWith("comment")) {
0870:                            if (protocols.containsKey("discussions")) {
0871:                                int count = Integer.parseInt((String) protocols
0872:                                        .get("discussions"));
0873:                                protocols.remove("discussions");
0874:                                protocols.put("discussions", Integer
0875:                                        .toString(count + 1));
0876:                            } else {
0877:                                protocols.put("discussions", "1");
0878:                            }
0879:                        } else {
0880:                            if (protocols.containsKey("other")) {
0881:                                int count = Integer.parseInt((String) protocols
0882:                                        .get("other"));
0883:                                protocols.remove("other");
0884:                                protocols.put("other", Integer
0885:                                        .toString(count + 1));
0886:                            } else {
0887:                                protocols.put("other", "1");
0888:                            }
0889:                        }
0890:                    }
0891:                }
0892:                return new Date();
0893:            }
0894:
0895:            private void saveStatistics(String name, Hashtable protocols,
0896:                    Hashtable servers, Date date) throws Exception {
0897:                syncDatabase();
0898:                for (int index = 0; index < databases.size(); index++) {
0899:                    SOIF s = (SOIF) databases.get(index);
0900:                    if (s.getURL().compareToIgnoreCase(name) == 0) {
0901:                        String str = s.getValue("DbStat-NbServer");
0902:                        if (str != null) {
0903:                            int total = Integer.parseInt(str);
0904:                            for (int i = 0; i < total; i++) {
0905:                                s.remove("DbStat-Href-count", i);
0906:                                s.remove("DbStat-Href", i);
0907:                            }
0908:                        }
0909:                        str = s.getValue("DbStat-NbProtocol");
0910:                        if (str != null) {
0911:                            int total = Integer.parseInt(str);
0912:                            for (int i = 0; i < total; i++) {
0913:                                s.remove("DbStat-Protocol-count", i);
0914:                                s.remove("DbStat-Protocol", i);
0915:                            }
0916:                        }
0917:
0918:                        SimpleDateFormat sdf = new SimpleDateFormat(
0919:                                "EEE, d MMM yyyy HH:mm:ss z");
0920:                        s.replace("DbStat-LastModified", (date != null) ? sdf
0921:                                .format(date) : sdf.format(new Date()));
0922:                        s.replace("DbStat-NbServer",
0923:                                (servers != null) ? Integer.toString(servers
0924:                                        .size()) : Integer.toString(0));
0925:                        s.replace("DbStat-NbProtocol",
0926:                                (protocols != null) ? Integer
0927:                                        .toString(protocols.size()) : Integer
0928:                                        .toString(0));
0929:                        if (servers != null) {
0930:                            Enumeration e = servers.keys();
0931:                            int i = 0;
0932:                            while (e.hasMoreElements()) {
0933:                                s.insert("DbStat-Href", (String) e
0934:                                        .nextElement(), i++);
0935:                            }
0936:
0937:                            e = servers.elements();
0938:                            i = 0;
0939:                            while (e.hasMoreElements()) {
0940:                                s.insert("DbStat-Href-count", (String) e
0941:                                        .nextElement(), i++);
0942:                            }
0943:                        }
0944:                        if (protocols != null) {
0945:                            Enumeration e = protocols.keys();
0946:                            int i = 0;
0947:                            while (e.hasMoreElements()) {
0948:                                s.insert("DbStat-Protocol", (String) e
0949:                                        .nextElement(), i++);
0950:                            }
0951:
0952:                            e = protocols.elements();
0953:                            i = 0;
0954:                            while (e.hasMoreElements()) {
0955:                                s.insert("DbStat-Protocol-count", (String) e
0956:                                        .nextElement(), i++);
0957:                            }
0958:                        }
0959:
0960:                        String fileName = searchServerRoot + File.separator
0961:                                + "tmp" + File.separator + "database."
0962:                                + Long.toString(System.currentTimeMillis());
0963:                        SOIFOutputStream os = new SOIFOutputStream(fileName);
0964:                        os.write(s);
0965:                        os.close();
0966:
0967:                        Process p = execute("rdmgr -D -y root -u -P -q "
0968:                                + fileName);
0969:                        p.waitFor();
0970:                        int exitValue = p.exitValue();
0971:                        if (exitValue != 0) {
0972:                            throw new Exception("Storing statistics for "
0973:                                    + name + " failed with " + exitValue);
0974:                        }
0975:                    }
0976:                }
0977:            }
0978:
0979:            private void syncDatabase() throws Exception {
0980:                boolean needUpdate = true;
0981:
0982:                if (lastDBUpdated != null) {
0983:                    String fileName = searchServerRoot + File.separator
0984:                            + "config" + File.separator + "search.conf";
0985:                    File f = new File(fileName);
0986:                    if (f.exists()) {
0987:                        if (lastSearchConfigUpdated == null
0988:                                || lastSearchConfigUpdated.before(new Date(f
0989:                                        .lastModified()))) {
0990:                            try {
0991:                                JMXConnector jmxc = AdminServerUtil
0992:                                        .getJMXConnector(host);
0993:                                MBeanServerConnection msc = jmxc
0994:                                        .getMBeanServerConnection();
0995:                                Object[] params = {};
0996:                                String[] signatures = {};
0997:                                msc.invoke(searchServerObjectName,
0998:                                        "loadConfig", params, signatures);
0999:                                searchDatabaseDir = (String) msc.getAttribute(
1000:                                        searchServerObjectName, "DatabaseDir");
1001:                            } catch (Exception e) {
1002:                                logger.log(Level.SEVERE, "PSSH_CSPSAMB0003", e);
1003:                            }
1004:                            lastSearchConfigUpdated = new Date();
1005:                        }
1006:                    }
1007:
1008:                    fileName = searchDatabaseDir + File.separator + "root"
1009:                            + File.separator + "rd.db";
1010:                    f = new File(fileName);
1011:                    if (f.exists()) {
1012:                        if (lastDBUpdated.after(new Date(f.lastModified()))) {
1013:                            logger.log(Level.SEVERE, "PSSH_CSPSAMB0002",
1014:                                    "no update");
1015:                            needUpdate = false;
1016:                        }
1017:                    }
1018:                }
1019:
1020:                if (needUpdate) {
1021:                    logger.log(Level.SEVERE, "PSSH_CSPSAMB0002", "update");
1022:                    databases = new ArrayList();
1023:
1024:                    Process p = execute("rdmgr -y root -U");
1025:                    SOIFInputStream is = new SOIFInputStream(
1026:                            p.getInputStream(), "UTF-8");
1027:                    while (!is.isEOS()) {
1028:                        SOIF s = is.readSOIF();
1029:                        if (s != null) {
1030:                            if (!s.getURL().equals("root")) {
1031:                                databases.add(s);
1032:                            }
1033:                        }
1034:                    }
1035:
1036:                    lastDBUpdated = new Date();
1037:                }
1038:            }
1039:
1040:            private Process execute(String options) throws Exception {
1041:                String command = searchServerRoot + File.separator
1042:                        + Platform.getCommand("run-cs-cli") + " " + options;
1043:
1044:                Runtime rt = Runtime.getRuntime();
1045:                Process p = rt.exec(command);
1046:                return p;
1047:            }
1048:
1049:            private boolean validateName(String name) {
1050:                if (name == null || name.length() == 0) {
1051:                    return false;
1052:                }
1053:
1054:                char[] c = name.toCharArray();
1055:                for (int index = 0; index < c.length; index++) {
1056:                    if (c[index] >= 'a' && c[index] <= 'z') {
1057:                        continue;
1058:                    }
1059:                    if (c[index] >= 'A' && c[index] <= 'Z') {
1060:                        continue;
1061:                    }
1062:                    if (c[index] >= '0' || c[index] <= '9') {
1063:                        continue;
1064:                    }
1065:                    if (c[index] == '_') {
1066:                        continue;
1067:                    }
1068:                    if (c[index] == '-') {
1069:                        continue;
1070:                    }
1071:                    return false;
1072:                }
1073:
1074:                return true;
1075:            }
1076:
1077:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.