/******************************************************************************* * Copyright (c) 2013, Perforce Software * All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ******************************************************************************/ package com.perforce.search.manager.impl; import java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import org.apache.log4j.Logger; import org.springframework.beans.factory.annotation.Autowired; import com.perforce.p4java.extension.exception.ServerAccessException; import com.perforce.p4java.extension.exception.ServerConnectionException; import com.perforce.p4java.extension.exception.ServerErrorException; import com.perforce.p4java.extension.operation.ChangesCommand; import com.perforce.p4java.extension.server.Server; import com.perforce.p4java.extension.utility.FormatUtility; import com.perforce.search.manager.ChangeCache; import com.perforce.search.server.ServerConnectionPoolFacade; public class ChangeCacheImpl implements ChangeCache { private Logger log = Logger.getLogger(ChangeCacheImpl.class); private ServerConnectionPoolFacade pool; private class ChangeData { @Autowired private String user; @Autowired private Date date; } private ConcurrentHashMap<String, ChangeData> changeToData; public ChangeCacheImpl(final ServerConnectionPoolFacade pool) { this.pool = pool; this.changeToData = new ConcurrentHashMap<String, ChangeData>(); } @Override public synchronized void addChanges(final List<String> changes) { Server server = null; try { // anything we don't have already? List<String> toFetch = new ArrayList<String>(); for (String change : changes) { if (changeToData.containsKey(change)) { continue; } assert (changeToData.get(change) == null); toFetch.add(String.format("@%s,@%s", change, change)); } if (toFetch.isEmpty()) { return; } final String[] fetchArray = toFetch.toArray(new String[toFetch .size()]); server = pool.acquireIndexer(); if (server == null) { log.error("Aborting, server = null"); return; } Map<String, Object>[] changeOutput = ChangesCommand.getChanges( fetchArray, server); for (Map<String, Object> change : changeOutput) { addChange((String) change.get(ChangesCommand.tagChange), change); } } catch (ServerConnectionException e) { log.error("failed to get changes", e); } catch (ServerAccessException e) { log.error("failed to get changes", e); } catch (ServerErrorException e) { log.error("failed to get changes", e); } finally { pool.release(server); } } @Override public synchronized void addChange(final String changeNum) { List<String> changes = new ArrayList<String>(); changes.add(changeNum); addChanges(changes); } private void addChange(final String changeNum, final Map<String, Object> change) { ChangeData data = new ChangeData(); data.user = (String) change.get("user"); data.date = FormatUtility.getDateFromLongInSeconds((String) change .get("time")); if (changeNum == null || data.user == null || data.date == null) { log.error(String.format("Missing data in addChange: %s %s %s", changeNum, data.user, data.date)); return; } changeToData.put(changeNum, data); } @Override public String getUser(final String change) { ChangeData data = changeToData.get(change); return (data != null) ? data.user : null; } @Override public Date getDate(final String change) { ChangeData data = changeToData.get(change); return (data != null) ? data.date : null; } @Override public void clearCache() { changeToData.clear(); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#2 | 8501 | Doug Scheirer |
* updating to gradlew for build * make (more) Mac compatible build process * default port for default install is now 8088 * updated API doc to include the queryRaw param on POSTs * minor bug fixes for when the p4d connection drops while indexing |
||
#1 | 8476 | Doug Scheirer | p4-search copy from //depot/main/p4-search |