Example usage for java.util.concurrent.atomic AtomicBoolean AtomicBoolean

List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean

Introduction

In this page you can find the example usage for java.util.concurrent.atomic AtomicBoolean AtomicBoolean.

Prototype

public AtomicBoolean(boolean initialValue) 

Source Link

Document

Creates a new AtomicBoolean with the given initial value.

Usage

From source file:com.github.brandtg.switchboard.LogPuller.java

/**
 * Pulls logs for a collection from a switchboard server.
 *
 * @param sourceAddress//w  ww  .j ava2s. c om
 *  The address of the switchboard server.
 * @param sinkAddress
 *  The address to provide as "target" in HTTP requests, on which to listen for data locally.
 * @param collection
 *  The name of the log.
 * @param lastIndex
 *  The last index consumed (-1 means nothing consumed).
 */
public LogPuller(InetSocketAddress sourceAddress, InetSocketAddress sinkAddress, String collection,
        long lastIndex) {
    this.sourceAddress = sourceAddress;
    this.sinkAddress = sinkAddress;
    this.collection = collection;
    this.lastIndex = lastIndex;
    this.isShutdown = new AtomicBoolean(false);
}

From source file:com.conwet.xjsp.session.ConnectionContext.java

public ConnectionContext(ConnectionState initialState, List<SessionListener> sessionListeners) {
    this.initialState = initialState;
    this.sessionListeners = sessionListeners;
    this.state = null;
    this.buffer = new StringBuilder();
    this.isOpen = new AtomicBoolean(Boolean.TRUE);
}

From source file:com.github.lynxdb.server.core.repository.TimeSerieRepo.java

public ChainableIterator<TimeSerie> find(UUID _vhost, String _name, Map<String, String> _tags, long _start,
        long _end) {

    return findRows(_vhost, _name, _tags, _start, _end).map(
            (ChainableIterator.Func1<ChainableIterator<TS>, TimeSerie>) (ChainableIterator<TS> _source) -> {
                Map<String, String> tags = new HashMap<>();
                AtomicBoolean tagsLoaded = new AtomicBoolean(false);

                return new TimeSerie(_name, tags, new ChainableIterator<Entry>() {

                    Iterator<Row> current = null;

                    @Override//from w  w  w  .j a va  2s.  c o  m
                    public boolean hasNext() {
                        if (current != null && current.hasNext()) {
                            return true;
                        }
                        while (_source.hasNext()) {
                            TS newTS = _source.next();
                            if (!tagsLoaded.get()) {
                                tagsLoaded.set(true);
                                tags.putAll(newTS.tags);
                            }
                            long start = System.currentTimeMillis();
                            current = ct.query(QueryBuilder.select("time", "value").from("series")
                                    .where(QueryBuilder.eq("vhostid", _vhost))
                                    .and(QueryBuilder.eq("name", _name))
                                    .and(QueryBuilder.eq("tags", newTS.serialized))
                                    .and(QueryBuilder.eq("group", newTS.group))
                                    .and(QueryBuilder.gte("time", _start)).and(QueryBuilder.lte("time", _end))
                                    .orderBy(QueryBuilder.desc("time"))).iterator();
                            csMonit.tsFetchQueryTime.add((int) (System.currentTimeMillis() - start));
                            csMonit.queryFetchCount.incrementAndGet();
                            if (current.hasNext()) {
                                return true;
                            }
                        }
                        return false;
                    }

                    @Override
                    public Entry next() {
                        Row r = current.next();
                        return new Entry(r.getInt("time"), r.getDouble("value"));
                    }
                });
            });
}

From source file:io.spring.initializr.web.support.SpringBootMetadataReaderTests.java

@Test
public void readAvailableVersions() throws IOException {
    this.server.expect(requestTo("https://spring.io/project_metadata/spring-boot")).andRespond(
            withSuccess(new ClassPathResource("metadata/sagan/spring-boot.json"), MediaType.APPLICATION_JSON));
    List<DefaultMetadataElement> versions = new SpringBootMetadataReader(this.objectMapper, this.restTemplate,
            this.metadata.getConfiguration().getEnv().getSpringBootMetadataUrl()).getBootVersions();
    assertThat(versions).as("spring boot versions should not be null").isNotNull();
    AtomicBoolean defaultFound = new AtomicBoolean(false);
    versions.forEach((it) -> {/*from  www.ja  v a 2s  .  c o  m*/
        assertThat(it.getId()).as("Id must be set").isNotNull();
        assertThat(it.getName()).as("Name must be set").isNotNull();
        if (it.isDefault()) {
            if (defaultFound.get()) {
                fail("One default version was already found " + it.getId());
            }
            defaultFound.set(true);
        }
    });
    this.server.verify();
}

From source file:com.github.thorbenlindhauer.math.MathUtil.java

public boolean isZeroMatrix() {

    final AtomicBoolean isZeroMatrix = new AtomicBoolean(true);

    // TODO: optimize to stop after first non-zero entry
    matrix.walkInOptimizedOrder(new DefaultRealMatrixPreservingVisitor() {

        @Override//from  w  w w .  ja v a  2  s  .  com
        public void visit(int row, int column, double value) {
            if (value > DOUBLE_COMPARISON_OFFSET || value < -DOUBLE_COMPARISON_OFFSET) {
                isZeroMatrix.set(false);
            }
        }
    });

    return isZeroMatrix.get();
}

From source file:com.agileapes.webexport.concurrent.impl.AbstractManager.java

@Override
public void shutdown() {
    running = new AtomicBoolean(false);
}

From source file:biz.ganttproject.impex.csv.CsvImportTest.java

public void testSkipEmptyLine() throws Exception {
    String header = "A, B";
    String data = "a1, b1";
    final AtomicBoolean wasCalled = new AtomicBoolean(false);
    RecordGroup recordGroup = new RecordGroup("AB", ImmutableSet.<String>of("A", "B")) {
        @Override/*ww w .  j  a v a  2s .co m*/
        protected boolean doProcess(CSVRecord record) {
            if (!super.doProcess(record)) {
                return false;
            }
            wasCalled.set(true);
            assertEquals("a1", record.get("A"));
            assertEquals("b1", record.get("B"));
            return true;
        }
    };
    GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, "", data)),
            recordGroup);
    importer.load();
    assertTrue(wasCalled.get());
}

From source file:com.github.brandtg.switchboard.LogReceiver.java

/**
 * A server that listens for log regions and pipes them to an output stream.
 *
 * @param address//w  ww . j  av a2  s . c  om
 *  The socket address on which to listen
 * @param eventExecutors
 *  The Netty executor service to use for incoming traffic
 * @param outputStream
 *  The output stream to which all data should be piped
 */
public LogReceiver(InetSocketAddress address, EventLoopGroup eventExecutors, final OutputStream outputStream) {
    this.address = address;
    this.isShutdown = new AtomicBoolean(true);
    this.listeners = new HashSet<Object>();
    this.serverBootstrap = new ServerBootstrap().group(eventExecutors).channel(NioServerSocketChannel.class)
            .childHandler(new ChannelInitializer<SocketChannel>() {
                @Override
                protected void initChannel(SocketChannel ch) throws Exception {
                    ch.pipeline()
                            .addLast(new LengthFieldBasedFrameDecoder(MAX_FRAME_LENGTH, LENGTH_FIELD_OFFSET,
                                    LENGTH_FIELD_LENGTH, LENGTH_ADJUSTMENT, INITIAL_BYTES_TO_STRIP));
                    ch.pipeline().addLast(new LogMessageHandler(outputStream, listeners));
                }
            });
}

From source file:com.quartzdesk.executor.dao.AbstractDao.java

/**
 * Checks if the specified table exists in the specified schema and returns true if
 * it exists, false otherwise. This method tries to look up the table using both
 * lower-case and upper-case schema and table names because some databases seems to
 * require the names to be in upper case (DB2, Oracle), whereas other databases require
 * the names to be in lower-case.//w  w w  .  ja  v a2  s.  co m
 *
 * @param session    a Hibernate session.
 * @param schemaName an optional schema name where to look for the table name.
 * @param tableName  a table name.
 * @return true if the table exists, false otherwise.
 */
public boolean tableExists(Session session, final String schemaName, final String tableName) {
    final AtomicBoolean tableExists = new AtomicBoolean(false);

    session.doWork(new Work() {
        @Override
        public void execute(Connection connection) throws SQLException {
            log.debug("Checking if table '{}' exists.", tableName);

            DatabaseMetaData metaData = connection.getMetaData();

            // 1. attempt - try schema and table name in lower-case (does not work in DB2 and Oracle)
            ResultSet res = metaData.getTables(null,
                    schemaName == null ? null : schemaName.toLowerCase(Locale.US),
                    tableName.toLowerCase(Locale.US), new String[] { "TABLE" });

            tableExists.set(res.next());
            DbUtils.close(res);

            if (tableExists.get()) {
                log.debug("Table '{}' exists.", tableName);
            } else {
                // 2. attempt - try schema and table name in upper-case (required for DB2 and Oracle)
                res = metaData.getTables(null, schemaName == null ? null : schemaName.toUpperCase(Locale.US),
                        tableName.toUpperCase(Locale.US), new String[] { "TABLE" });

                tableExists.set(res.next());
                DbUtils.close(res);

                if (tableExists.get()) {
                    log.debug("Table '{}' exists.", tableName);
                } else {
                    log.debug("Table '{}' does not exist.", tableName);
                }
            }
        }
    });

    return tableExists.get();
}

From source file:io.github.jeddict.jpa.modeler.properties.convert.ConvertPanel.java

@Override
public Convert getValue() {
    AtomicBoolean validated = new AtomicBoolean(false);
    importAttributeConverter(converter_EditorPane.getText(), validated, modelerFile);
    if (!validated.get()) {
        throw new IllegalStateException();
    }//  w w w . j  a  v a  2s. co  m
    convert.setConverter(converter_EditorPane.getText());
    convert.setAttributeName(null);
    convert.setDisableConversion(disableConversion_CheckBox.isSelected());
    return convert;
}