首页

关于jetspeed源码包中JetspeedIdGenerator序列生成器源码说明

标签:jetspeed,JetspeedIdGenerator,序列生成器     发布时间:2018-11-09   

一、前言

关于jetspeed-id-generator2.2.2)源码中org.apache.jetspeed.idgenerator.JetspeedIdGenerator序列生成器,详情参见源码说明。

二、源码说明

package org.apache.jetspeed.idgenerator;@b@@b@import org.slf4j.Logger;@b@import org.slf4j.LoggerFactory;@b@@b@public class JetspeedIdGenerator@b@  implements IdGenerator@b@{@b@  private static final Logger log = LoggerFactory.getLogger(JetspeedIdGenerator.class);@b@  private static final long DEFAULT_CONFIG_COUNTER_START = 65536L;@b@  private static final String DEFAULT_CONFIG_PEID_PREFIX = "P-";@b@  private static final String DEFAULT_CONFIG_PEID_SUFFIX = "";@b@  private String peidPrefix = null;@b@  private String peidSuffix = null;@b@  protected long idCounter;@b@@b@  public JetspeedIdGenerator()@b@  {@b@    this.idCounter = 65536L;@b@    this.peidPrefix = "P-";@b@    this.peidSuffix = "";@b@  }@b@@b@  public JetspeedIdGenerator(long counterStart)@b@  {@b@    this.idCounter = counterStart;@b@    this.peidPrefix = "P-";@b@    this.peidSuffix = "";@b@  }@b@@b@  public JetspeedIdGenerator(long counterStart, String prefix, String suffix)@b@  {@b@    this.idCounter = counterStart;@b@    this.peidPrefix = prefix;@b@    this.peidSuffix = suffix;@b@  }@b@@b@  public void start()@b@  {@b@    log.info("Start JetspeedIdGenerator");@b@  }@b@@b@  public void stop()@b@  {@b@    log.info("Shutdown for JetspeedIdGenerator called. idCounter = " + this.idCounter + " (" + Long.toHexString(this.idCounter) + ")");@b@  }@b@@b@  public String getNextPeid()@b@  {@b@    long newid;@b@    synchronized (JetspeedIdGenerator.class)@b@    {@b@      newid = this.idCounter++;@b@    }@b@@b@    return this.peidPrefix + Long.toHexString(System.currentTimeMillis()) + "-" + Long.toHexString(newid) + this.peidSuffix;@b@  }@b@}