Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hello,
Does anyone has an example on how you have implemented the reset of an enumeration list.
I have a class that generate a list of wtpart in a text file. But I need to stop windchill and clear the cache to gets the new data.
I'm trying to use this method but I'm struggling to get the EnumerationInfoProvider.
EnumerationInfomanager.resetEnumeration(EnumerationInfoProvider)
If anyone has an example it will be great.
Note I used the following code to generate my list:
https://www.ptc.com/en/support/article?n=CS138327&source=subscription
thanks
Try adding this to your initialize method, I included some context to show source of some variable names. Every time initialize runs, it sets a timer to expire the cache. Note that after resetEnumeration is called, the cache will be marked as expired on the server, and the initialize only runs again the next time it is needed. At that moment, the cache will be fresh, and the timer resets.
...
import wt.session.SessionContext;
import wt.session.SessionThread;
...
public class Replace_With_Class_Name_Of_This_EnumerationInfoProvider implements EnumerationInfoProvider {
...
private static final String ENUMERATION_NAME = "Your Enumeration Name";
private EnumerationInfoManager enumInfoManager = null;
private String parameters = null;
private static final AtomicLong threadNumber = new AtomicLong();
...
public void initialize(EnumerationInfoManager manager, String params) {
...
Runnable cacheResetSessionThread = new Runnable () {
public void run () {
try {
// Note this runs once and exits - because after clearing cache, its job is done. The next time data is needed, the server will
// call initialize again, which will run this code again.
long timerDelay = 30 * 60 * 1000L; // in milliseconds
Thread.sleep(timerDelay);
if(enumInfoManager != null) {
enumInfoManager.resetEnumeration(Replace_With_Class_Name_Of_This_EnumerationInfoProvider.this);
}
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
e.printStackTrace();
}
}
};
String sessionThreadName = ENUMERATION_NAME+"-"+threadNumber.incrementAndGet();
SessionThread sessionThread = new SessionThread(cacheResetSessionThread, new SessionContext(),sessionThreadName);
sessionThread.start();
I found another way to reset/refresh the External Enumerated Value Lists:
I put every instance that Windchill creates, in a private static list.
Then it's possible to iterate over this list and ask for a refresh for every instance.
I performed this by calling the public static method: refreshList() from a main() that invokes the method server.
In source code I omitted the implementation and I put just what it is useful for your purpose.
public class CustomEnumInfoProvider implements EnumerationInfoProvider, RemoteAccess {
private static final DebugLogger logger = new DebugLogger(LogR.getLogger(CustomEnumInfoProvider.class.getName()));
private static List<CustomEnumInfoProvider> instances = new ArrayList<>();
private static final Locale[] SUPPORTED_LOCALES = { Locale.US, Locale.ENGLISH, Locale.ITALIAN };
private static final Locale DEFAULT_LOCALE = Locale.US;
private String instanceName = "CEIP_" + String.valueOf(System.currentTimeMillis());
private EnumerationInfoManager enumInfoManager = null;
private String parameters = null;
private EnumerationInfo enumerationInfo = null;
public String getInstanceName() {
return instanceName;
}
@Override
public EnumerationInfoManager getManager() {
return this.enumInfoManager;
}
@Override
public EnumerationInfo getEnumerationInfo() {
return enumerationInfo;
}
@Override
public String getParameters() {
return this.parameters;
}
public CustomEnumInfoProvider() {
instances.add(this);
logger.debug("Created new instance: " + this.getInstanceName());
}
@Override
public void initialize(EnumerationInfoManager manager, String params) {
if (manager == null) {
String errorMsg = "Argument EnumerationInfoManager must be not null.";
throw new IllegalArgumentException(errorMsg);
}
this.enumInfoManager = manager;
this.parameters = params;
logger.debug("this.enumInfoManager: " + this.enumInfoManager);
logger.debug("this.parameters: " + this.parameters);
try {
this.enumerationInfo = createEnumerationInfo();
logger.debug("EnumerationInfo Initialized!");
} catch (Exception e) {
logger.error("Error creating EnumerationInfo object: " + e.toString());
e.printStackTrace();
}
}
public static void main(String[] args) {
try {
if (args.length < 2) {
System.out.println("Passare come argomenti: utente password");
System.exit(0);
}
String userName = args[0];
String password = args[1];
RemoteMethodServer server = MethodServerUtil.connectToMethodServer(userName, password);
Class<?> classFind[] = {};
Object objFind[] = {};
boolean res = (boolean) server.invoke("refreshList", CustomEnumInfoProvider.class.getName(), null,
classFind, objFind);
if (res)
System.out.println("Refresh degli elenchi effettuato!");
else
System.out.println("Errore durante il Refresh degli elenchi: verificare nel log del method server.");
} catch (Exception e) {
e.printStackTrace();
}
}
public static boolean refreshList() {
boolean result = false;
try {
for (CustomEnumInfoProvider item : instances) {
logger.debug("Refreshing instance: " + item.getInstanceName());
item.getManager().resetEnumeration(item);
logger.debug("Done!");
}
result = true;
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}