Fix CodeQL warning-severity alerts: missed wakeups, resource leaks, escaping threads (#790)
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.forgerock.opendj.config.client; |
| | | |
| | |
| | | * @return Returns the first exception that caused this exception. |
| | | */ |
| | | @Override |
| | | public PropertyException getCause() { |
| | | public synchronized PropertyException getCause() { |
| | | return causes.iterator().next(); |
| | | } |
| | | |
| | |
| | | * information: "Portions copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.forgerock.opendj.security; |
| | | |
| | |
| | | } |
| | | |
| | | private static ConnectionFactory newLDIFConnectionFactory(final File ldifFile) throws IOException { |
| | | try (LDIFEntryReader reader = new LDIFEntryReader(new FileReader(ldifFile)).setSchema(SCHEMA)) { |
| | | try (FileReader ldifFileReader = new FileReader(ldifFile); |
| | | LDIFEntryReader reader = new LDIFEntryReader(ldifFileReader).setSchema(SCHEMA)) { |
| | | final MemoryBackend backend = new MemoryBackend(SCHEMA, reader).enableVirtualAttributes(true); |
| | | return newInternalConnectionFactory(new WriteLDIFOnUpdateRequestHandler(backend, ldifFile)); |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2015-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.forgerock.opendj.maven.doc; |
| | | |
| | |
| | | */ |
| | | private Map<String, String> getAciDescriptions() throws IOException { |
| | | final Map<String, String> descriptions = new HashMap<>(); |
| | | BufferedReader reader = new BufferedReader(new FileReader(configDotLdif)); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | if (line.startsWith("# @aci ")) { |
| | | String[] split = line.replace("# @aci ", "").split(":", 2); |
| | | descriptions.put(split[0], split[1]); |
| | | try (FileReader fileReader = new FileReader(configDotLdif); |
| | | BufferedReader reader = new BufferedReader(fileReader)) { |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | | if (line.startsWith("# @aci ")) { |
| | | String[] split = line.replace("# @aci ", "").split(":", 2); |
| | | descriptions.put(split[0], split[1]); |
| | | } |
| | | } |
| | | } |
| | | return descriptions; |
| | |
| | | * @throws IOException Failed to read the LDIF. |
| | | */ |
| | | private void readAcis(Map<String, String> descriptions) throws IOException { |
| | | LDIFEntryReader reader = new LDIFEntryReader(new FileInputStream(configDotLdif)); |
| | | reader.setIncludeBranch(DN.valueOf("cn=Access Control Handler,cn=config")); |
| | | try (FileInputStream configStream = new FileInputStream(configDotLdif); |
| | | LDIFEntryReader reader = new LDIFEntryReader(configStream)) { |
| | | reader.setIncludeBranch(DN.valueOf("cn=Access Control Handler,cn=config")); |
| | | |
| | | while (reader.hasNext()) { |
| | | Entry entry = reader.readEntry(); |
| | | for (String attribute : entry.parseAttribute("ds-cfg-global-aci").asSetOfString()) { |
| | | Aci aci = new Aci(); |
| | | aci.name = getName(attribute); |
| | | if (descriptions != null) { |
| | | aci.description = descriptions.get(aci.name); |
| | | while (reader.hasNext()) { |
| | | Entry entry = reader.readEntry(); |
| | | for (String attribute : entry.parseAttribute("ds-cfg-global-aci").asSetOfString()) { |
| | | Aci aci = new Aci(); |
| | | aci.name = getName(attribute); |
| | | if (descriptions != null) { |
| | | aci.description = descriptions.get(aci.name); |
| | | } |
| | | aci.definition = AsciidocConverterUtils.escapeVerticalLine(attribute); |
| | | allGlobalAcis.add(aci); |
| | | } |
| | | aci.definition = AsciidocConverterUtils.escapeVerticalLine(attribute); |
| | | allGlobalAcis.add(aci); |
| | | } |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2015 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | final String userName = args[2]; |
| | | final char[] password = args[3].toCharArray(); |
| | | |
| | | // Create the LDIF reader using either the named file, if provided, or stdin. |
| | | InputStream ldif; |
| | | // Read the LDIF from either the named file, if provided, or stdin. Only a file is closed |
| | | // here; stdin belongs to the caller. |
| | | final String[] ldifLines; |
| | | if (args.length > 4) { |
| | | try { |
| | | ldif = new FileInputStream(args[4]); |
| | | try (InputStream ldif = new FileInputStream(args[4])) { |
| | | ldifLines = getInputLines(ldif); |
| | | } catch (final FileNotFoundException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue()); |
| | | return; |
| | | } catch (final IOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue()); |
| | | return; |
| | | } |
| | | } else { |
| | | ldif = System.in; |
| | | ldifLines = getInputLines(System.in); |
| | | } |
| | | final String[] ldifLines = getInputLines(ldif); |
| | | |
| | | // Connect to the server, bind, and request the modifications. |
| | | new LDAPConnectionFactory(hostName, port) |
| | |
| | | * |
| | | * Copyright 2009-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.examples; |
| | |
| | | |
| | | // Create the memory backend. |
| | | final MemoryBackend backend; |
| | | try { |
| | | backend = new MemoryBackend(new LDIFEntryReader(new FileInputStream(ldifFileName))); |
| | | try (FileInputStream ldifStream = new FileInputStream(ldifFileName); |
| | | LDIFEntryReader ldifReader = new LDIFEntryReader(ldifStream)) { |
| | | backend = new MemoryBackend(ldifReader); |
| | | } catch (final IOException e) { |
| | | System.err.println(e.getMessage()); |
| | | System.exit(ResultCode.CLIENT_SIDE_PARAM_ERROR.intValue()); |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap.tools; |
| | |
| | | import java.io.InputStream; |
| | | import java.io.InputStreamReader; |
| | | import java.io.PrintStream; |
| | | import java.io.Reader; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | |
| | | dataToDecode = encodedDataArg.getValue(); |
| | | } else { |
| | | final boolean readFromFile = encodedDataFilePathArg.isPresent(); |
| | | Reader source = null; |
| | | BufferedReader reader = null; |
| | | final String encodedDataFilePath = encodedDataFilePathArg.getValue(); |
| | | try { |
| | | reader = new BufferedReader(readFromFile ? new FileReader(encodedDataFilePath) |
| | | : new InputStreamReader(System.in)); |
| | | // Only a file is closed below; System.in belongs to the caller. |
| | | source = readFromFile ? new FileReader(encodedDataFilePath) |
| | | : new InputStreamReader(System.in); |
| | | reader = new BufferedReader(source); |
| | | final StringBuilder buffer = new StringBuilder(); |
| | | String line; |
| | | while ((line = reader.readLine()) != null) { |
| | |
| | | ERR_BASE64_CANNOT_READ_ENCODED_DATA.get(getExceptionMessage(e))); |
| | | } finally { |
| | | if (readFromFile) { |
| | | closeSilently(reader); |
| | | closeSilently(reader, source); |
| | | } |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.forgerock.opendj.reactive; |
| | | |
| | |
| | | // so notify here to allow the server startup to complete. |
| | | synchronized (waitListen) { |
| | | starting = false; |
| | | waitListen.notify(); |
| | | waitListen.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | // At this point, the connection Handler either started correctly or failed |
| | | // to start but the start process should be notified and resume its work in any cases. |
| | | synchronized (waitListen) { |
| | | waitListen.notify(); |
| | | waitListen.notifyAll(); |
| | | } |
| | | |
| | | // If we have gotten here, then we are about to start listening |
| | |
| | | connectionPool = cpool; |
| | | connectionPool.addReferralAuthenticationListener(this); |
| | | |
| | | refreshQueue = new NodeSearcherQueue("New red", 2); |
| | | refreshQueue = new NodeSearcherQueue("New red", 2).start(); |
| | | |
| | | // NUMSUBORDINATE HACK |
| | | // Create an empty hacker to avoid null value test. |
| | |
| | | private final List<AbstractNodeTask> waitingQueue = new ArrayList<>(); |
| | | private final Map<BasicNode, AbstractNodeTask> workingList = new HashMap<>(); |
| | | private final ThreadGroup threadGroup; |
| | | private final List<Thread> threads = new ArrayList<>(); |
| | | |
| | | |
| | | /** |
| | |
| | | for (int i = 0; i < threadCount; i++) { |
| | | Thread t = new Thread(threadGroup, this, name + "[" + i + "]"); |
| | | t.setPriority(Thread.MIN_PRIORITY); |
| | | threads.add(t); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Starts the threads consuming this queue. |
| | | * <p> |
| | | * The threads are not started by the constructor so that {@code this} is not published to them |
| | | * before construction has completed. |
| | | * |
| | | * @return this queue |
| | | */ |
| | | public NodeSearcherQueue start() { |
| | | for (Thread t : threads) { |
| | | t.start(); |
| | | } |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new IllegalArgumentException("null argument"); |
| | | } |
| | | waitingQueue.add(nodeTask); |
| | | notify(); |
| | | notifyAll(); |
| | | // System.out.println("Queued " + nodeTask + " in " + _name); |
| | | } |
| | | |
| | |
| | | if (task != null) { |
| | | task.cancel(); |
| | | } |
| | | notify(); |
| | | notifyAll(); |
| | | } |
| | | |
| | | /** |
| | |
| | | throw new IllegalArgumentException("null argument"); |
| | | } |
| | | workingList.remove(task.getNode()); |
| | | notify(); |
| | | notifyAll(); |
| | | // System.out.println("Flushed " + task + " from " + _name); |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package org.opends.guitools.controlpanel.ui; |
| | |
| | | } |
| | | synchronized (entryReaderThread) |
| | | { |
| | | entryReaderThread.notify(); |
| | | entryReaderThread.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.guitools.controlpanel.ui.components; |
| | | |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void addMouseListener(MouseListener mouseListener) |
| | | public synchronized void addMouseListener(MouseListener mouseListener) |
| | | { |
| | | super.addMouseListener(mouseListener); |
| | | if (mouseListeners == null) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void removeMouseListener(MouseListener mouseListener) |
| | | public synchronized void removeMouseListener(MouseListener mouseListener) |
| | | { |
| | | super.removeMouseListener(mouseListener); |
| | | mouseListeners.remove(mouseListener); |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package org.opends.guitools.controlpanel.ui.components; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void addActionListener(ActionListener listener) |
| | | public synchronized void addActionListener(ActionListener listener) |
| | | { |
| | | listeners.add(listener); |
| | | } |
| | | |
| | | @Override |
| | | public void removeActionListener(ActionListener listener) |
| | | public synchronized void removeActionListener(ActionListener listener) |
| | | { |
| | | listeners.remove(listener); |
| | | } |
| | |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.quicksetup; |
| | | |
| | |
| | | ProcessBuilder pb = new ProcessBuilder(args); |
| | | InputStream is = null; |
| | | OutputStream out = null; |
| | | BufferedReader reader = null; |
| | | final boolean[] done = {false}; |
| | | try { |
| | | Map<String, String> env = pb.environment(); |
| | |
| | | }); |
| | | t.start(); |
| | | } |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | reader = new BufferedReader(new InputStreamReader(is)); |
| | | String line = reader.readLine(); |
| | | bi.values.put(NAME, line); |
| | | StringBuilder sb = new StringBuilder(); |
| | |
| | | |
| | | } finally { |
| | | done[0] = true; |
| | | StaticUtils.close(is, out); |
| | | StaticUtils.close(reader, is, out); |
| | | } |
| | | |
| | | // Make sure we got values for important properties that are used |
| | |
| | | application.notifyListeners(LocalizableMessage.raw(line)); |
| | | application.notifyListeners(application.getLineBreak()); |
| | | } |
| | | }; |
| | | }.start(); |
| | | |
| | | final BufferedReader out = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | new OutputReader(out) |
| | |
| | | application.notifyListeners(LocalizableMessage.raw(line)); |
| | | application.notifyListeners(application.getLineBreak()); |
| | | } |
| | | }; |
| | | }.start(); |
| | | |
| | | return process.waitFor(); |
| | | } |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | |
| | | package org.opends.quicksetup.util; |
| | |
| | | */ |
| | | public abstract void processLine(String line); |
| | | |
| | | private final Thread thread; |
| | | |
| | | /** |
| | | * The protected constructor. |
| | | * <p> |
| | | * The reader is consumed until end of stream and then closed by this reader's thread, which is |
| | | * only launched by {@link #start()}. |
| | | * |
| | | * @param reader the BufferedReader of the stop process. |
| | | */ |
| | | public OutputReader(final BufferedReader reader) { |
| | | Thread t = new Thread(new Runnable() { |
| | | thread = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | try (BufferedReader in = reader) { |
| | | String line; |
| | | while (null != (line = reader.readLine())) { |
| | | while (null != (line = in.readLine())) { |
| | | processLine(line); |
| | | } |
| | | } catch (Throwable t) { |
| | |
| | | } |
| | | } |
| | | }); |
| | | t.start(); |
| | | } |
| | | |
| | | /** |
| | | * Starts consuming the reader in a background thread. |
| | | * <p> |
| | | * The thread is not started by the constructor so that {@code this} does not escape before |
| | | * construction of the subclass has completed. |
| | | * |
| | | * @return this reader |
| | | */ |
| | | public OutputReader start() { |
| | | thread.start(); |
| | | return this; |
| | | } |
| | | } |
| | |
| | | Thread t = new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | String line = reader.readLine(); |
| | | // The reader is owned by this thread, which closes it once the stream is drained. |
| | | try (BufferedReader in = reader) { |
| | | String line = in.readLine(); |
| | | while (line != null) { |
| | | if (application != null) { |
| | | LocalizableMessageBuilder buf = new LocalizableMessageBuilder(); |
| | |
| | | isFirstLine = false; |
| | | } |
| | | logger.info(LocalizableMessage.raw("server: " + line)); |
| | | line = reader.readLine(); |
| | | line = in.readLine(); |
| | | } |
| | | } catch (Throwable t) { |
| | | if (application != null) { |
| | |
| | | @Override |
| | | public void run() |
| | | { |
| | | try |
| | | // The reader is owned by this thread, which closes it once the stream is drained. |
| | | try (BufferedReader in = reader) |
| | | { |
| | | String line = reader.readLine(); |
| | | String line = in.readLine(); |
| | | while (line != null) |
| | | { |
| | | if (application != null) { |
| | |
| | | isFinished = true; |
| | | startedIdFound = true; |
| | | } |
| | | line = reader.readLine(); |
| | | line = in.readLine(); |
| | | } |
| | | } catch (Throwable t) |
| | | { |
| | |
| | | final Process process = pb.start(); |
| | | logger.info(LocalizableMessage.raw("launching " + args + " with env: " + env)); |
| | | InputStream is = process.getInputStream(); |
| | | BufferedReader reader = new BufferedReader(new InputStreamReader(is)); |
| | | String line; |
| | | boolean errorDetected = false; |
| | | while (null != (line = reader.readLine())) |
| | | try (BufferedReader reader = new BufferedReader(new InputStreamReader(is))) |
| | | { |
| | | logger.info(LocalizableMessage.raw("The output: " + line)); |
| | | if (line.contains("ERROR: The detected Java version")) |
| | | String line; |
| | | while (null != (line = reader.readLine())) |
| | | { |
| | | if (isWindows()) |
| | | logger.info(LocalizableMessage.raw("The output: " + line)); |
| | | if (line.contains("ERROR: The detected Java version")) |
| | | { |
| | | // If we are running windows, the process get blocked waiting for |
| | | // user input. Just wait for a certain time to print the output |
| | | // in the logger and then kill the process. |
| | | Thread t = new Thread(new Runnable() |
| | | if (isWindows()) |
| | | { |
| | | @Override |
| | | public void run() |
| | | // If we are running windows, the process get blocked waiting for |
| | | // user input. Just wait for a certain time to print the output |
| | | // in the logger and then kill the process. |
| | | Thread t = new Thread(new Runnable() |
| | | { |
| | | try |
| | | @Override |
| | | public void run() |
| | | { |
| | | Thread.sleep(3000); |
| | | // To see if the process is over, call the exitValue method. |
| | | // If it is not over, a IllegalThreadStateException. |
| | | process.exitValue(); |
| | | try |
| | | { |
| | | Thread.sleep(3000); |
| | | // To see if the process is over, call the exitValue method. |
| | | // If it is not over, a IllegalThreadStateException. |
| | | process.exitValue(); |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | process.destroy(); |
| | | } |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | process.destroy(); |
| | | } |
| | | } |
| | | }); |
| | | t.start(); |
| | | }); |
| | | t.start(); |
| | | } |
| | | errorDetected = true; |
| | | } |
| | | errorDetected = true; |
| | | } |
| | | } |
| | | process.waitFor(); |
| | |
| | | Application app) |
| | | throws FileNotFoundException, IllegalArgumentException |
| | | { |
| | | this(new FileInputStream(zipFile), |
| | | // The name is validated before the stream is opened, otherwise the stream would leak when the |
| | | // validation fails. |
| | | this(openZipFile(zipFile), |
| | | minRatio, |
| | | maxRatio, |
| | | numberZipEntries, |
| | | zipFile.getName(), |
| | | app); |
| | | } |
| | | |
| | | private static FileInputStream openZipFile(File zipFile) throws FileNotFoundException |
| | | { |
| | | if (!zipFile.getName().endsWith(".zip")) { |
| | | throw new IllegalArgumentException("File must have extension .zip"); |
| | | } |
| | | return new FileInputStream(zipFile); |
| | | } |
| | | |
| | | /** |
| | |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.backends.pluggable; |
| | | |
| | |
| | | { |
| | | is = new InflaterInputStream(is); |
| | | } |
| | | byte[] data = new byte[encodedEntryLen]; |
| | | int readBytes; |
| | | int position = 0; |
| | | int leftToRead = encodedEntryLen; |
| | | // CipherInputStream does not read more than block size... |
| | | do |
| | | try (InputStream entryStream = is) |
| | | { |
| | | if ((readBytes = is.read(data, position, leftToRead)) == -1 ) |
| | | byte[] data = new byte[encodedEntryLen]; |
| | | int readBytes; |
| | | int position = 0; |
| | | int leftToRead = encodedEntryLen; |
| | | // CipherInputStream does not read more than block size... |
| | | do |
| | | { |
| | | throw DecodeException.error(ERR_CANNOT_DECODE_ENTRY.get()); |
| | | } |
| | | position += readBytes; |
| | | leftToRead -= readBytes; |
| | | } while (leftToRead > 0 && readBytes > 0); |
| | | return Entry.decode(ByteString.wrap(data).asReader(), compressedSchema); |
| | | if ((readBytes = entryStream.read(data, position, leftToRead)) == -1 ) |
| | | { |
| | | throw DecodeException.error(ERR_CANNOT_DECODE_ENTRY.get()); |
| | | } |
| | | position += readBytes; |
| | | leftToRead -= readBytes; |
| | | } while (leftToRead > 0 && readBytes > 0); |
| | | return Entry.decode(ByteString.wrap(data).asReader(), compressedSchema); |
| | | } |
| | | } |
| | | catch (CryptoManagerException cme) |
| | | { |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2014 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.backends.task; |
| | | |
| | |
| | | |
| | | synchronized (notifyLock) |
| | | { |
| | | notifyLock.notify(); |
| | | notifyLock.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2025 3A Systems,LLC |
| | | * Portions Copyright 2025-2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.config; |
| | | |
| | |
| | | { |
| | | byte[] buffer = new byte[8192]; |
| | | try(FileInputStream inputStream = new FileInputStream(configFile); |
| | | GZIPOutputStream outputStream = new GZIPOutputStream(new FileOutputStream(archiveFile))) |
| | | FileOutputStream archiveStream = new FileOutputStream(archiveFile); |
| | | GZIPOutputStream outputStream = new GZIPOutputStream(archiveStream)) |
| | | { |
| | | int bytesRead = inputStream.read(buffer); |
| | | while (bytesRead > 0) |
| | |
| | | } |
| | | |
| | | @Override |
| | | public void abort(CancelRequest cancelRequest) |
| | | public synchronized void abort(CancelRequest cancelRequest) |
| | | { |
| | | if(cancelResult == null && this.cancelRequest == null) |
| | | { |
| | |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | public MemberList getMembers() |
| | | throws DirectoryException |
| | | { |
| | | return new DynamicGroupMemberList(groupEntryDN, memberURLs); |
| | | return new DynamicGroupMemberList(groupEntryDN, memberURLs).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | { |
| | | if (baseDN == null && filter == null) |
| | | { |
| | | return new DynamicGroupMemberList(groupEntryDN, memberURLs); |
| | | return new DynamicGroupMemberList(groupEntryDN, memberURLs).start(); |
| | | } |
| | | else |
| | | { |
| | | return new DynamicGroupMemberList(groupEntryDN, memberURLs, baseDN, scope, |
| | | filter); |
| | | filter).start(); |
| | | } |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.extensions; |
| | | |
| | |
| | | */ |
| | | private final LinkedBlockingQueue<Object> resultQueue; |
| | | |
| | | /** The background thread which performs the internal searches. */ |
| | | private final DynamicGroupSearchThread searchThread; |
| | | |
| | | /** The search filter to use when filtering the set of group members. */ |
| | | private final SearchFilter filter; |
| | | |
| | |
| | | } |
| | | } |
| | | |
| | | DynamicGroupSearchThread searchThread = |
| | | searchThread = |
| | | new DynamicGroupSearchThread(this, baseDNArray, filterArray, urlArray); |
| | | } |
| | | |
| | | /** |
| | | * Starts the background searches which populate this member list. |
| | | * <p> |
| | | * The searches are not started by the constructor so that {@code this} is not published to the |
| | | * search thread before construction has completed. |
| | | * |
| | | * @return this member list |
| | | */ |
| | | DynamicGroupMemberList start() |
| | | { |
| | | searchThread.start(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | private String name; |
| | | private AtomicBoolean stopRequested; |
| | | private WriterThread writerThread; |
| | | private final WriterThread writerThread; |
| | | |
| | | private boolean autoFlush; |
| | | |
| | |
| | | |
| | | this.queue = new LinkedBlockingQueue<>(capacity); |
| | | this.capacity = capacity; |
| | | this.writerThread = null; |
| | | this.stopRequested = new AtomicBoolean(false); |
| | | |
| | | writerThread = new WriterThread(); |
| | | writerThread.start(); |
| | | |
| | | DirectoryServer.registerShutdownListener(this); |
| | | } |
| | | |
| | | /** |
| | | * Starts the background thread which publishes the queued log records. |
| | | * <p> |
| | | * The thread is not started by the constructor so that {@code this} is not published to it before |
| | | * construction has completed. |
| | | * |
| | | * @return this writer |
| | | */ |
| | | AsynchronousTextWriter start() |
| | | { |
| | | writerThread.start(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * The publisher thread is responsible for emptying the queue of log records |
| | | * waiting to published. |
| | | */ |
| | |
| | | stopRequested.set(true); |
| | | |
| | | // Wait for publisher thread to terminate |
| | | while (writerThread != null && writerThread.isAlive()) { |
| | | while (writerThread.isAlive()) { |
| | | try { |
| | | // Interrupt the thread if its blocking |
| | | writerThread.interrupt(); |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | this.stopRequested = false; |
| | | |
| | | rotaterThread = new RotaterThread(this); |
| | | rotaterThread.start(); |
| | | |
| | | DirectoryServer.registerShutdownListener(this); |
| | | } |
| | | |
| | | /** |
| | | * Starts the background thread which rotates and retains the log files. |
| | | * <p> |
| | | * The thread is not started by the constructor so that {@code this} is not published to it before |
| | | * construction has completed. |
| | | * |
| | | * @return this writer |
| | | */ |
| | | MultifileTextWriter start() |
| | | { |
| | | rotaterThread.start(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Construct a PrintWriter for a file. |
| | | * @param file - the file to open for writing |
| | | * @param filePermissions - the file permissions to set on the file. |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | theWriter.addRetentionPolicy(DirectoryServer.getRetentionPolicy(dn)); |
| | | } |
| | | |
| | | // Rotation only starts once the policies above are registered. |
| | | theWriter.start(); |
| | | |
| | | if (cfg.isAsynchronous()) |
| | | { |
| | | this.writer = newAsyncWriter(theWriter, cfg); |
| | |
| | | private AsynchronousTextWriter newAsyncWriter(MultifileTextWriter mfWriter, FileBasedAccessLogPublisherCfg config) |
| | | { |
| | | String name = "Asynchronous Text Writer for " + config.dn(); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | writer.addRetentionPolicy(DirectoryServer.getRetentionPolicy(dn)); |
| | | } |
| | | |
| | | // Rotation only starts once the policies above are registered. |
| | | writer.start(); |
| | | |
| | | if (cfg.isAsynchronous()) |
| | | { |
| | | this.writer = newAsyncWriter(writer, cfg); |
| | |
| | | private AsynchronousTextWriter newAsyncWriter(MultifileTextWriter writer, FileBasedAuditLogPublisherCfg cfg) |
| | | { |
| | | String name = "Asynchronous Text Writer for " + cfg.dn(); |
| | | return new AsynchronousTextWriter(name, cfg.getQueueSize(), cfg.isAutoFlush(), writer); |
| | | return new AsynchronousTextWriter(name, cfg.getQueueSize(), cfg.isAutoFlush(), writer).start(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | writer.addRetentionPolicy(DirectoryServer.getRetentionPolicy(dn)); |
| | | } |
| | | |
| | | // Rotation only starts once the policies above are registered. |
| | | writer.start(); |
| | | |
| | | if(config.isAsynchronous()) |
| | | { |
| | | this.writer = newAsyncWriter(writer, config); |
| | |
| | | private AsynchronousTextWriter newAsyncWriter(MultifileTextWriter writer, FileBasedDebugLogPublisherCfg config) |
| | | { |
| | | String name = "Asynchronous Text Writer for " + config.dn(); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), writer); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), writer).start(); |
| | | } |
| | | |
| | | private void configure(MultifileTextWriter mfWriter, FileBasedDebugLogPublisherCfg config) throws DirectoryException |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | writer.addRetentionPolicy(DirectoryServer.getRetentionPolicy(dn)); |
| | | } |
| | | |
| | | // Rotation only starts once the policies above are registered. |
| | | writer.start(); |
| | | |
| | | if(config.isAsynchronous()) |
| | | { |
| | | this.writer = newAsyncWriter(writer, config); |
| | |
| | | private AsynchronousTextWriter newAsyncWriter(MultifileTextWriter mfWriter, FileBasedErrorLogPublisherCfg config) |
| | | { |
| | | String name = "Asynchronous Text Writer for " + config.dn(); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter).start(); |
| | | } |
| | | |
| | | private void setDefaultSeverities(Set<ErrorLogPublisherCfgDefn.DefaultSeverity> defSevs) |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.loggers; |
| | | |
| | |
| | | private AsynchronousTextWriter newAsyncWriter(MultifileTextWriter mfWriter, FileBasedHTTPAccessLogPublisherCfg config) |
| | | { |
| | | String name = "Asynchronous Text Writer for " + config.dn(); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter); |
| | | return new AsynchronousTextWriter(name, config.getQueueSize(), config.isAutoFlush(), mfWriter).start(); |
| | | } |
| | | |
| | | private LocalizableMessage setLogFormatFields(String logFormat) |
| | |
| | | theWriter.addRetentionPolicy(DirectoryServer.getRetentionPolicy(dn)); |
| | | } |
| | | |
| | | // Rotation only starts once the policies above are registered. |
| | | theWriter.start(); |
| | | |
| | | if (cfg.isAsynchronous()) |
| | | { |
| | | this.writer = newAsyncWriter(theWriter, cfg); |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.plugins.profiler; |
| | | |
| | |
| | | */ |
| | | public void processDataFile(String filename) throws IOException |
| | | { |
| | | // Try to open the file for reading. |
| | | ASN1Reader reader = ASN1.getReader(new FileInputStream(filename)); |
| | | |
| | | |
| | | try |
| | | // Both resources are declared here so that the file stream is closed as well if the reader |
| | | // cannot be created around it. |
| | | try (FileInputStream fileStream = new FileInputStream(filename); |
| | | ASN1Reader reader = ASN1.getReader(fileStream)) |
| | | { |
| | | // The first element in the file must be a sequence with the header |
| | | // information. |
| | |
| | | existingFrame.recurseSubFrames(stack, pos-1, count, stacksByMethod); |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | close(reader); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.protocols.http; |
| | | |
| | |
| | | */ |
| | | private final Object waitListen = new Object(); |
| | | |
| | | /** |
| | | * The condition guarding {@link #waitListen}: set once the run method has tried to open the |
| | | * socket port, whether it succeeded or not. Guarded by {@link #waitListen}. |
| | | */ |
| | | private boolean listenAttempted; |
| | | |
| | | /** The friendly name of this connection handler. */ |
| | | private String friendlyName; |
| | | |
| | |
| | | |
| | | try |
| | | { |
| | | waitListen.wait(); |
| | | while (!listenAttempted) |
| | | { |
| | | waitListen.wait(); |
| | | } |
| | | } |
| | | catch (InterruptedException e) |
| | | { |
| | | // If something interrupted the start its probably better to return ASAP |
| | | Thread.currentThread().interrupt(); |
| | | } |
| | | } |
| | | } |
| | |
| | | synchronized (waitListen) |
| | | { |
| | | starting = false; |
| | | waitListen.notify(); |
| | | listenAttempted = true; |
| | | waitListen.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | // to start but the start process should be notified and resume its work in any cases. |
| | | synchronized (waitListen) |
| | | { |
| | | waitListen.notify(); |
| | | listenAttempted = true; |
| | | waitListen.notifyAll(); |
| | | } |
| | | |
| | | // If we have gotten here, then we are about to start listening |
| | |
| | | { |
| | | starting = false; |
| | | listenAttempted = true; |
| | | waitListen.notify(); |
| | | waitListen.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | synchronized (waitListen) |
| | | { |
| | | listenAttempted = true; |
| | | waitListen.notify(); |
| | | waitListen.notifyAll(); |
| | | } |
| | | |
| | | // If none of the listeners were created successfully, then |
| | |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.replication.plugin; |
| | | |
| | |
| | | flushThread.initiateShutdown(); |
| | | synchronized (flushThread) |
| | | { |
| | | flushThread.notify(); |
| | | flushThread.notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | */ |
| | | if (msgQueue.isEmpty()) |
| | | { |
| | | msgQueue.notify(); |
| | | msgQueue.notifyAll(); |
| | | } |
| | | |
| | | msgQueue.add(update); |
| | |
| | | synchronized (msgQueue) |
| | | { |
| | | msgQueue.clear(); |
| | | msgQueue.notify(); |
| | | msgQueue.notifyAll(); |
| | | } |
| | | |
| | |
| | | { |
| | | ReplicationServerDomain domain = baseDNs.get(baseDN); |
| | | if (domain == null && create) { |
| | | domain = new ReplicationServerDomain(baseDN, this); |
| | | domain = new ReplicationServerDomain(baseDN, this).start(); |
| | | baseDNs.put(baseDN, domain); |
| | | } |
| | | return domain; |
| | |
| | | } |
| | | |
| | | // Wake up connect thread. |
| | | connectThreadLock.notify(); |
| | | connectThreadLock.notifyAll(); |
| | | } |
| | | |
| | | // Wait until the connect thread has processed next connect phase. |
| | |
| | | this.domainDB = |
| | | localReplicationServer.getChangelogDB().getReplicationDomainDB(); |
| | | this.statusAnalyzer = new StatusAnalyzer(this); |
| | | this.statusAnalyzer.start(); |
| | | DirectoryServer.registerMonitorProvider(this); |
| | | } |
| | | |
| | | /** |
| | | * Starts the status analyzer of this domain. |
| | | * <p> |
| | | * The analyzer is not started by the constructor so that {@code this} is not published to its |
| | | * thread before construction has completed. |
| | | * |
| | | * @return this domain |
| | | */ |
| | | ReplicationServerDomain start() |
| | | { |
| | | statusAnalyzer.start(); |
| | | return this; |
| | | } |
| | | |
| | | /** |
| | | * Add an update that has been received to the list of |
| | | * updates that must be forwarded to all other servers. |
| | | * |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.replication.server.changelog.file; |
| | | |
| | |
| | | { |
| | | synchronized (this) |
| | | { |
| | | notify(); |
| | | notifyAll(); |
| | | } |
| | | } |
| | | } |
| | |
| | | super.initiateShutdown(); |
| | | synchronized (this) |
| | | { |
| | | notify(); |
| | | notifyAll(); |
| | | } |
| | | } |
| | | |
| | |
| | | // wait until clear() has been done by thread, always waking it up |
| | | synchronized (this) |
| | | { |
| | | notify(); |
| | | notifyAll(); |
| | | } |
| | | // ensures thread wait that this thread's state is cleaned up |
| | | Thread.yield(); |
| | |
| | | final ChangelogDBPurger currentPurger = cnPurger.get(); |
| | | synchronized (currentPurger) |
| | | { |
| | | currentPurger.notify(); |
| | | currentPurger.notifyAll(); |
| | | } |
| | | } |
| | | } |
| | |
| | | super.initiateShutdown(); |
| | | synchronized (this) |
| | | { |
| | | notify(); // wake up the purger thread for faster shutdown |
| | | notifyAll(); // wake up the purger thread for faster shutdown |
| | | } |
| | | } |
| | | } |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.replication.server.changelog.file; |
| | | |
| | |
| | | if (isWriteEnabled) |
| | | { |
| | | ensureLogFileIsValid(parser); |
| | | writer = BlockLogWriter.newWriter(new LogWriter(logfile), parser); |
| | | initializeNewestRecord(); |
| | | final LogWriter logWriter = new LogWriter(logfile); |
| | | try |
| | | { |
| | | writer = BlockLogWriter.newWriter(logWriter, parser); |
| | | initializeNewestRecord(); |
| | | } |
| | | catch (ChangelogException | RuntimeException e) |
| | | { |
| | | // The writer is not reachable from a half-constructed log file, so close it here. |
| | | StaticUtils.close(logWriter); |
| | | throw e; |
| | | } |
| | | } |
| | | else |
| | | { |
| | |
| | | final ConnectedRS rs = connectedRS.get(); |
| | | if (rs.isConnected()) |
| | | { |
| | | connectPhaseLock.notify(); |
| | | connectPhaseLock.notifyAll(); |
| | | |
| | | final long rsGenId = rs.rsInfo.getGenerationId(); |
| | | final int rsServerId = rs.rsInfo.getServerId(); |
| | |
| | | if (!connectionError) |
| | | { |
| | | connectionError = true; |
| | | connectPhaseLock.notify(); |
| | | connectPhaseLock.notifyAll(); |
| | | |
| | | if (!rsInfos.isEmpty()) |
| | | { |
| | |
| | | synchronized (monitorResponse) |
| | | { |
| | | monitorResponse.set(true); |
| | | monitorResponse.notify(); |
| | | monitorResponse.notifyAll(); |
| | | } |
| | | |
| | | // Update the replication servers ServerStates with new received info |
| | |
| | | { |
| | | synchronized (update) |
| | | { |
| | | update.notify(); |
| | | update.notifyAll(); |
| | | } |
| | | |
| | | // Analyze status of embedded in the ack to see if everything went well |
| | |
| | | * |
| | | * Copyright 2006-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.tasks; |
| | | |
| | |
| | | private String domainString; |
| | | private int source; |
| | | private LDAPReplicationDomain domain; |
| | | private TaskState initState; |
| | | /** |
| | | * The monitor used to signal the completion of the import to {@link #runTask()}. |
| | | * <p> |
| | | * A dedicated lock is required because {@link #initState} is reassigned: synchronizing on the |
| | | * state itself would lock the monitor of an enum constant which is both shared JVM wide and |
| | | * different for the waiting and the notifying thread. |
| | | */ |
| | | private final Object initStateLock = new Object(); |
| | | private volatile TaskState initState; |
| | | |
| | | /** The total number of entries expected to be processed when this import will end successfully. */ |
| | | private long total; |
| | |
| | | // launch the import |
| | | domain.initializeFromRemote(source, this); |
| | | |
| | | synchronized(initState) |
| | | synchronized (initStateLock) |
| | | { |
| | | // Waiting for the end of the job |
| | | while (initState == TaskState.RUNNING) |
| | | { |
| | | initState.wait(1000); |
| | | initStateLock.wait(1000); |
| | | replaceAttributeValue(ATTR_TASK_INITIALIZE_LEFT, String.valueOf(left)); |
| | | replaceAttributeValue(ATTR_TASK_INITIALIZE_DONE, String.valueOf(total-left)); |
| | | } |
| | |
| | | finally |
| | | { |
| | | // Wake up runTask method waiting for completion |
| | | synchronized (initState) |
| | | synchronized (initStateLock) |
| | | { |
| | | initState.notify(); |
| | | initStateLock.notifyAll(); |
| | | } |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2008-2010 Sun Microsystems, Inc. |
| | | * Portions Copyright 2011-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.tools; |
| | | |
| | |
| | | { |
| | | String serviceName = null; |
| | | Process p = Runtime.getRuntime().exec(cmd); |
| | | BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream())); |
| | | boolean processDone = false; |
| | | String s; |
| | | while (!processDone) |
| | | try (BufferedReader stdout = new BufferedReader(new InputStreamReader(p.getInputStream()))) |
| | | { |
| | | try |
| | | boolean processDone = false; |
| | | String s; |
| | | while (!processDone) |
| | | { |
| | | p.exitValue(); |
| | | processDone = true; |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | while ((s = stdout.readLine()) != null) |
| | | { |
| | | serviceName = s; |
| | | if (serviceName.trim().length() == 0) |
| | | try |
| | | { |
| | | serviceName = null; |
| | | p.exitValue(); |
| | | processDone = true; |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | while ((s = stdout.readLine()) != null) |
| | | { |
| | | serviceName = s; |
| | | if (serviceName.trim().length() == 0) |
| | | { |
| | | serviceName = null; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | { |
| | | int resultCode = -1; |
| | | Process process = new ProcessBuilder(cmd).start(); |
| | | BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream())); |
| | | |
| | | boolean processDone = false; |
| | | String s; |
| | | while (!processDone) |
| | | try (BufferedReader stdout = new BufferedReader(new InputStreamReader(process.getInputStream()))) |
| | | { |
| | | try |
| | | boolean processDone = false; |
| | | String s; |
| | | while (!processDone) |
| | | { |
| | | resultCode = process.exitValue(); |
| | | processDone = true; |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | while ((s = stdout.readLine()) != null) |
| | | { |
| | | if (s.trim().length() != 0) |
| | | try |
| | | { |
| | | serviceName = s; |
| | | resultCode = process.exitValue(); |
| | | processDone = true; |
| | | } |
| | | catch (Throwable t) |
| | | { |
| | | } |
| | | while ((s = stdout.readLine()) != null) |
| | | { |
| | | if (s.trim().length() != 0) |
| | | { |
| | | serviceName = s; |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2015-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.tools.makeldif; |
| | | |
| | |
| | | /** The queue used to hold generated entries until they can be read. */ |
| | | private LinkedBlockingQueue<TemplateEntry> entryQueue; |
| | | |
| | | /** The background thread used to actually generate the entries. */ |
| | | private final MakeLDIFInputStreamThread generatorThread; |
| | | |
| | | /** |
| | | * Creates a new MakeLDIF input stream that will generate entries based on the |
| | | * provided template file. |
| | | * |
| | | * @param templateFile The template file to use to generate the entries. |
| | | */ |
| | | public MakeLDIFInputStream(TemplateFile templateFile) |
| | | private MakeLDIFInputStream(TemplateFile templateFile) |
| | | { |
| | | allGenerated = false; |
| | | closed = false; |
| | |
| | | } |
| | | |
| | | /* The background thread being used to actually generate the entries. */ |
| | | new MakeLDIFInputStreamThread(this, templateFile).start(); |
| | | generatorThread = new MakeLDIFInputStreamThread(this, templateFile); |
| | | } |
| | | |
| | | /** |
| | | * Creates a new MakeLDIF input stream based on the provided template file and starts generating |
| | | * entries in the background. |
| | | * <p> |
| | | * The generator thread is started here rather than by the constructor so that {@code this} is not |
| | | * published to it before construction has completed. |
| | | * |
| | | * @param templateFile The template file to use to generate the entries. |
| | | * |
| | | * @return A new input stream which has started generating entries. |
| | | */ |
| | | public static MakeLDIFInputStream newStartedInputStream(TemplateFile templateFile) |
| | | { |
| | | MakeLDIFInputStream inputStream = new MakeLDIFInputStream(templateFile); |
| | | inputStream.generatorThread.start(); |
| | | return inputStream; |
| | | } |
| | | |
| | | |
| | |
| | | * information: "Portions Copyright [year] [name of copyright owner]". |
| | | * |
| | | * Portions Copyright 2013-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.tools.upgrade; |
| | | |
| | |
| | | import org.forgerock.opendj.ldif.LDIFEntryReader; |
| | | import org.forgerock.opendj.ldif.LDIFEntryWriter; |
| | | import org.forgerock.util.Reject; |
| | | import org.forgerock.util.Utils; |
| | | import org.opends.server.core.DirectoryServer; |
| | | import org.opends.server.util.ChangeOperationType; |
| | | import org.opends.server.util.SchemaUtils; |
| | |
| | | { |
| | | final Schema schema = getUpgradeSchema(); |
| | | final File configFile = new File(configDirectory, CURRENT_CONFIG_FILE_NAME); |
| | | final LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema); |
| | | return LDIF.search(entryReader, searchRequest, schema); |
| | | final FileInputStream configStream = new FileInputStream(configFile); |
| | | try |
| | | { |
| | | // Ownership of the stream passes to the returned reader, which the caller must close. |
| | | final LDIFEntryReader entryReader = new LDIFEntryReader(configStream).setSchema(schema); |
| | | return LDIF.search(entryReader, searchRequest, schema); |
| | | } |
| | | catch (RuntimeException e) |
| | | { |
| | | Utils.closeSilently(configStream); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | |
| | | int changeCount = 0; |
| | | final Schema schema = getUpgradeSchema(); |
| | | try (LDIFEntryReader entryReader = new LDIFEntryReader(new FileInputStream(configFile)).setSchema(schema); |
| | | LDIFEntryWriter writer = new LDIFEntryWriter(new FileOutputStream(copyConfig))) |
| | | try (FileInputStream configStream = new FileInputStream(configFile); |
| | | LDIFEntryReader entryReader = new LDIFEntryReader(configStream).setSchema(schema); |
| | | FileOutputStream copyStream = new FileOutputStream(copyConfig); |
| | | LDIFEntryWriter writer = new LDIFEntryWriter(copyStream)) |
| | | { |
| | | writer.setWrapColumn(80); |
| | | |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2012-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | |
| | | */ |
| | | public LDIFImportConfig(TemplateFile templateFile) |
| | | { |
| | | this(new MakeLDIFInputStream(templateFile)); |
| | | this(MakeLDIFInputStream.newStartedInputStream(templateFile)); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | if (isCompressed) |
| | | { |
| | | inputStream = new GZIPInputStream(inputStream); |
| | | inputStream = wrapWithGzip(inputStream); |
| | | } |
| | | |
| | | reader = new BufferedReader(new InputStreamReader(inputStream), |
| | |
| | | return reader; |
| | | } |
| | | |
| | | /** |
| | | * Wraps the provided stream for decompression, closing it if the wrapping fails so that the |
| | | * underlying file descriptor is not leaked. |
| | | */ |
| | | private static InputStream wrapWithGzip(final InputStream inputStream) throws IOException |
| | | { |
| | | try |
| | | { |
| | | return new GZIPInputStream(inputStream); |
| | | } |
| | | catch (IOException | RuntimeException e) |
| | | { |
| | | StaticUtils.close(inputStream); |
| | | throw e; |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | |
| | | if (isCompressed) |
| | | { |
| | | inputStream = new GZIPInputStream(inputStream); |
| | | inputStream = wrapWithGzip(inputStream); |
| | | } |
| | | |
| | | reader = new BufferedReader(new InputStreamReader(inputStream), bufferSize); |
| | |
| | | * |
| | | * Copyright 2006-2009 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2015 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.types; |
| | | |
| | |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void mark(int i) { |
| | | public synchronized void mark(int i) { |
| | | parentStream.mark(i); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | | @Override |
| | | public void reset() throws IOException { |
| | | public synchronized void reset() throws IOException { |
| | | parentStream.reset(); |
| | | } |
| | | |
| | |
| | | * |
| | | * Copyright 2006-2008 Sun Microsystems, Inc. |
| | | * Portions Copyright 2014-2016 ForgeRock AS. |
| | | * Portions Copyright 2026 3A Systems, LLC. |
| | | */ |
| | | package org.opends.server.backends.jeb; |
| | | |
| | |
| | | ArrayList<LocalizableMessage> warnings = new ArrayList<>(); |
| | | templateFile.parse(template, warnings); |
| | | MakeLDIFInputStream ldifEntryStream = |
| | | new MakeLDIFInputStream(templateFile); |
| | | MakeLDIFInputStream.newStartedInputStream(templateFile); |
| | | LDIFReader reader = |
| | | new LDIFReader(new LDIFImportConfig(ldifEntryStream)); |
| | | for(int i =0; i<numEntries;i++) { |